01 - Binary Systems
01 - Binary Systems
0907231
★ Introduction
★ Digital Logic
★ Numbering Systems
★ Binary Coding
2
Introduction
Early Computers
★ Mechanical /
Electromechanical
● Made of gears and livers
rather than electronics
● Heavily used in World War
II to crack communication
codes
★ Limitations Most famous is the
● huge Babbage Machine
developed in the early
● slow 1800s.
● prone to wear
● limited functionality
4
Early Computers
★ Electronic Analogue
● 1950s - 1960s
● Built using resistors, capacitors,
inductors, potentiometers, and
amplifiers
★ Analogue
● Uses voltages and currents that take
continuous range of values
★ Limitations
● AC and DC offset
● susceptible to noise
● sensitive to temperature
5
Early Computers – The Transistor Revolution
★ The transistor was invented by William Shockley, John Bardeen
and Walter Brattain at Bell Labs in 1956.
★ A transistor can be used in two different ways:
● Linear operation: can be used to build amplifiers and Analogue
Computers
● Switch Operation: Acts like a normal switch (ON or OFF), i.e.
passes or blocks current from flowing. Used to build digital
computers.
★ These two states ON and OFF are binary states. Use 1 and 0 to
represent them and use binary arithmetic to understand complex
operations
★ Binary arithmetic and simple digital circuits are the topic of
this course
6
Analogue Computer Systems
★ Built using resistors, amplifiers, capacitors and inductors and
others.
★ Use analogue Voltages and Currents to represent information
● There is a value at every point in time (x-axis) (continuous-time)
● There is a range of values for the (y-axis) (continuous-range)
★ Takes a set of continuous information inputs and continuous
internal information (system state) and generates a set of
continuous information outputs.
Analogue
Computer
7
Digital Systems & Computers
★ Takes a set of discrete information inputs and discrete internal
information (system state) and generates a set of discrete information
outputs.
Memory
Control
CPU unit Datapath
Inputs Outputs
keyboard, mouse, Input/Output LCD screen,
wireless, wireless,
microphone speakers
10
Digital System Example
A Digital Counter (e. g., odometer):
Count Up
Reset 0 0 1 3 5 64
11
Digital System Example
Embedded Systems
★ Computers are integral parts of other products
★ Examples of embedded computers
● Microcomputers
● Microcontrollers
● Digital signal processors
★ Examples of embedded systems applications
Digital Electronics
Computer Organization and
Architecture II
13
Digital Logic
What is Digital Logic?
★ Digital
Digital 🡺 Digit 🡺 Finger 🡺 Discrete & Finite
● Examples
♦ the alphabet (A, B … etc)
♦ 10 decimal digits (0, 1, 2 … etc)
● Combine together
♦ Words are made of letters (University … etc)
♦ Numbers are made of digits (4241 … etc)
15
What is Digital Logic?
★ Logic
● In digital systems, variables may take on discrete and finite values
● Two level, or binary values are the most prevalent values in digital
systems
★ Binary Logic Representation
● Digits 0 and 1
● False (F) and True (T)
● Low (L) and High (H)
● On and Off
★ Why binary logic?
● Can be easily implemented in electronic circuits
● Has higher noise immunity
16
Digital Logic
★ How to represent 0 and 1 physically?
● CPU 🡺 Voltage
● CD 🡺 Surface Pits/Light
17
Digital Logic
★ Representation using voltage
Forbidden State
The voltage must not remain here for
too long, otherwise, undefined output
(no guarantees what the output is)
No guarantees what
the output might be!
18
Digital Logic
★ Representation using voltage
( dN-1dN-2…d2d1d0 . d-1d-2…d-M )r
Integer Fraction
● Where di belongs to { 0, 1, 2, 3, … , r-1 }
★ Digit Position N-1 1 0 -1 -M
… …
★ Digit Weight
rN-1 r1 r0 r-1 r-M
● Weight = (Base) Position … …
21
Number Systems
★ Magnitude in decimal
● Sum of “Digit × Weight”
22
Examples
★ (213)4 = ( )10
★ (55.3)6 = ( )10
23
Decimal Number System
★ Base (also called radix) = 10
● 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
★ Digit Position 2 1 0 -1 -2
★ (11.101)2 = ( )10
26
Octal Number System
★ Base = 8
● 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
★ Weights 64 8 1 1/8 1/64
27
Hexadecimal Number System
★ Base = 16
A, B, C, D, E, F
● 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15}
★ Weights 256 16 1 1/16 1/256
28
Examples
★ (56.4)8 = ( )10
★ (2D.8)16 = ( )10
29
The Power of 2
n 2n n 2n
0 20=1 8 28=256
1 21=2 9 29=512
2 22=4 10 210=1024 Kilo
3 23=8 11 211=2048
4 24=16 12 212=4096
5 25=32 20 220=1M Mega
★ (12HK)21 = (???)10
33
Conversion between
Numbering Systems
Number Base Conversions
Evaluate
Magnitude
Octal
(Base 8)
Evaluate
Magnitude
Decimal Binary
(Base 10) (Base 2)
Hexadeci
mal
(Base 16)
Evaluate
Magnitude 35
Decimal (Integer) to Base r Conversion
★ Divide the number by the ‘Base’ (=r)
★ Take the remainder as a coefficient
★ Take the quotient and repeat the division until
quotient is zero
Example: (13)10 =(???)2
Quotient Remainder Coefficient
13/ 2 = 6 1 a0 = 1
6 /2= 3 0 a1 = 0
3 /2= 1 1 a2 = 1
1 /2= 0 1 a3 = 1
Answer: (13)10 = (a3 a2 a1 a0)2 = (1101)2
MSB LSB 36
Examples
★ (156)10 = ( )2
37
Examples
★ (77)10 = ( )2
Quotient
38
Examples
★ (55)10 = ( )3
Quotient
39
Examples
★ (99)10 = ( )16
Quotient
40
Decimal (Fraction) to Base r Conversion
★ Multiply the number by the ‘Base’ (=r)
★ Take the integer as a coefficient
★ Take the resultant fraction and repeat the
multiplication until fractional part is zero
Example: (0.125)10=(???)2
Integer Fraction Coefficient
0.125 * 2 = 0 . 25 a-1 = 0
0.25 * 2 = 0 . 5 a-2 = 0
0.5 *2= 1 . 0 a-3 = 1
Answer: (0.125)10 = (0.a-1 a-2 a-3)2 = (0.001)2
MSB LSB 41
Examples
★ (0.64)10 = ( )5
42
Examples
★ (0.6875)10 = ( )2
★ (0.6)10 = ( )4
43
Examples
★ (15.625)10 = ( )8
Quotient
44
Binary − Octal Conversion
★ 8 = 23 Octal Binary
★ Each group of 3 bits represents 0 000
an octal digit 1 001
2 010
Assume Zeros
Example: 3 011
( 1 0 1 1 0 . 0 1 )2 4 100
5 101
6 110
( 2 6 . 2 )8 7 111
47
Examples
★ ( 10 1110 1001 0010 . 0110 1101 1 )2 = ( )16
★ (F13 . 67)16 = ( )2
48
Octal − Hexadecimal Conversion
★ Convert to Binary as an intermediate step
Example:
( 2 6 . 2 )8
( 0 1 0 1 1 0 . 0 1 0 )2
(1 6 . 4 )16
50
Examples
★ (212 . 1)3 = ( )9
51
Binary Coding
Binary Codes
★ Represent/encode information using combinations
of 0 and 1 (code word) as long as data is uniquely
encoded
★ May represent numeric data
● Must represent the needed range of values
● Representation should make arithmetic operations
straightforward
★ May represent non-numeric data
● Greater flexibility since arithmetic operations not
applied
● Not tied to binary numbers
53
Binary Codes
★ Group of n bits
● Up to M=2n combinations/codes
● Each combination represents an element of information
● Example (n=3)
♦ 000, 001, 010, 011, 100, 101, 110, 111
★ To encode M elements
● Need bits
● Example. How many bits are required to encode the
decimal numbers?
♦ M = 10 🡺
54
Binary Codes
★ To represent M elements we need bits
● M = 4 with n = 2
♦ We have four possible combinations only
♦ 00, 01, 10, 11
★ However, we can use more bits!
● M = 4 with n = 4
♦ We have 16 possible combinations
♦ 0000, 0001, 0010, 0011 … 1111
♦ Pick any four combinations to encode!
♦ One-hot code 🡺 0001, 0010, 0100, 1000
55
Binary Codes
★ Effectively, there are 8008 ways to encode the
decimal numbers using 4 bits, i.e. 8008 codes!
Decimal 8, 4, 2, 1 Excess-3 8, 4, -2, -1 Gray
0 0000 0011 0000 0000
1 0001 0100 0111 0001
2 0010 0101 0110 0011
3 0011 0110 0101 0010
4 0100 0111 0100 0110
5 0101 1000 1011 1110
6 0110 1001 1010 1010
7 0111 1010 1001 1011
8 1000 1011 1000 1001
9 1001 1100 1111 1000
56
Binary Codes
★ Binary Coded Decimal (BCD) Decimal
0
BCD
0000
● Each Decimal Digit is represented 1 0001
by 4 bits 2 0010
3 0011
● (0 – 9) ⇨ Valid combinations 4 0100
5 0101
● (10 – 15) ⇨ Invalid combinations 6 0110
7 0111
● It can be thought of as weighted code!
8 1000
★ Example 9 1001
(58)10 🡺 BCD?
57
Warning!
★ Coding or Conversion?
● Do NOT mix up conversion of a decimal number to a
binary number with coding a decimal number with a
BINARY CODE.
★ 1310 = 11012 (This is conversion)
58
Excess-3 Code
★ Excess-3 = Binary + 3
Decimal Binary Excess 3 Can figure out the relation
between the codes of 0 and
0 0000 0011
9, 1 and 8, 2 and 7 …. ?
1 0001 0100
Complement Code!
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
59
8, 4, -2, -1 Code
★ Decimal value = 8 × B3+ 4 × B2 – 2 × B1 – 1 × B0
Decimal Binary 8, 4, -2, -1 Can you figure out the
relation between the codes
0 0000 0000
of 0 and 9, 1 and 8, 2 and 7
1 0001 0111 …. ?
2 0010 0110
Complement Code!
3 0011 0101
4 0100 0100
5 0101 1011
6 0110 1010
7 0111 1001
8 1000 1000
9 1001 1111
60
ASCII Code
★ American Standard Code for Information Interchange
★ Non-numeric. This code is a popular code used to represent information
sent as character-based data
★ It uses 7-bits (i.e. 128 characters) to represent:
● 95 Graphic printing characters
– 26 upper case letters (A-Z)
– 26 lower case letters (a-z)
– 10 numerals (0-9)
– 33 special characters (e.g. %, @, $)
● 33 Non-printing characters
– Format effectors: used for text format (e.g. BS = Backspace, CR = carriage
return)
– Information separators: used to separate the data into paragraphs and pages
(e.g. RS = record separator, FS = file separator)
– Communication control characters (e.g. STX and ETX start and end text
areas).
61
ASCII Table
62
ASCII Code
★ ASCII has some interesting properties:
● Digits 0 to 9 span Hexadecimal values 3016 to 3916
63
Unicode Code
★ Non-numeric
64
Error Detecting Codes
★ Parity
One bit added to a group of bits to make the total number
of ‘1’s (including the parity bit) even or odd
Even
1 0 1 1 1 0 1 0 0 0 0 0 1
Odd
0 0 1 1 1 1 1 0 0 0 0 0 1
65
Error Detecting Codes
★ Good for checking odd number of errors
★ Example
● Assume even parity Number of
ones is
odd?
Error
1 001 1 000
Transmitter Receiver
Parity Data Parity Data
66
Gray Code
★ None-numeric code Decimal Binary Gray
0 0000 0000
1 0001 0001
2 0010 0011
★ What is special about 3 0011 0010
4 0100 0110
gray code? 5 0101 0111
6 0110 0101
● One bit changes from 7 0111 0100
one code to the next 8 1000 1100
code 9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
67
Gray Code
★ How to generate n binary gray Decimal BCD Gray
0 0000 0000
code?
1 0001 0001
★ For the first n/2 codes 2 0010 0011
70