Professional Documents
Culture Documents
0907231
Adapted from Dr. Bassam Kahhaleh’ Slides by
Prof. Iyad Jafar
Chapter 1
Binary Systems
Outline
Introduction
Digital Logic
Numbering Systems
Conversion between Numbering Systems
Binary Coding
3
Introduction
Early Computers - Mechanical / Electromechanical
Made of gears and livers rather than electronics
Heavily used in World War II to crack communication codes
Most famous is the Babbage Machine developed in the early
1800s.
Huge, slow, prone to wear, limited
functionality.
Yet, in 2016, NASA announced that
its Automaton Rover for Extreme
Environments program would use a
mechanical computer to operate in
the harsh environmental conditions
found on Venus
5
Early Computers - Electronic Analogue
Computer systems back in the 1950s and
1960s
Built using traditional circuits
containing resistors, capacitors,
inductors, potentiometers, and amplifiers
Analogue: use voltages and currents that
take continuous range of values
Limitations: AC and DC offset,
susceptible to noise, sensitive to
temperature (different output if
temperature fluctuates)
6
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 (You
will learn this in Electronics)
● Switch Operation: Acts like a normal switch (ON or OFF), i.e. passes or blocks
current from flowing. Used to build digital computers that all modern computer
circuits use.
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
7
The Big Picture
Computer Organization and
Digital Logic Architecture I
Electronics I and II
Build Processing Units, ALUs, instructions,
understand floating point arithmetic, etc.
8
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
9
Digital Systems & Computers
Takes a set of discrete information inputs and discrete internal
information (system state) and generates a set of discrete information
outputs.
14
12
10
Value
8
6
4
2
0
0 2 4 6 8 10 12
Time
Memory
Control
CPU unit Datapath
Inputs Outputs
microphone speakers
12
Digital System Example
A Digital Counter (e. g., odometer):
Count Up
Reset 0 0 1 3 5 64
13
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
16
Digital 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
● 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
● Have higher noise immunity
17
Digital Logic
How to represent 0 and 1 physically?
● CPU Voltage
● CD Surface Pits/Light
18
Digital Logic
Representation using voltage
Forbidden State
No guarantees what
the output might be!
19
Digital Logic
Representation using voltage
Integer Fraction
● Where di belongs to { 0, 1, 2, 3, … , r-1 }
… …
Example
● (123.2)5
23
Examples
(213)4 = ( )10
(55.3)6 = ( )10
24
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
(10110)2 = ( )10
(11.101)2 = ( )10
27
Octal Number System
Base = 8
● 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
Weights 64 8 1 1/8 1/64
28
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
29
Examples
(56.4)8 = ( )10
(2D.8)16 = ( )10
30
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
34
Conversion between
Numbering Systems
Number Base Conversions
Evaluate
Magnitude
Octal
(Base 8)
Evaluate
Magnitude
Decimal Binary
(Base 10) (Base 2)
Hexadecimal
(Base 16)
Evaluate
Magnitude
36
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 37
Examples
(156)10 = ( )2
38
Examples
(77)10 = ( )2
39
Examples
(55)10 = ( )3
40
Examples
(99)10 = ( )16
41
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.625)10=(???)2
Integer Fraction Coefficient
0.625 * 2 = 1 . 25 a-1 = 1
0.25 * 2 = 0 . 5 a-2 = 0
0.5 *2= 1 . 0 a-3 = 1
Answer: (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2
MSB LSB 42
Examples
(0.64)10 = ( )5
43
Examples
(0.6875)10 = ( )2
44
Examples
(15.625)10 = ( )8
45
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
(7563.1102)8 = ( )2
( 011011110101100.01011 )2 = ( )8
48
Examples
( 10111010010010.011011011 )2 = ( )16
(F13.67)16 = ( )2
49
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
(6503.21)8 = ( )16
51
Examples
(212.1)3 = ( )9
52
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
54
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
4 bits
55
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
56
Binary Codes
Effectively, there are 8000 ways to encode the
decimal numbers using 4 bits, i.e. 8000 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
57
Binary Codes
Decimal BCD
Binary Coded Decimal (BCD) 0 0000
● Each Decimal Digit is represented 1 0001
2 0010
by 4 bits 3 0011
4 0100
● (0 – 9) Valid combinations 5 0101
● (10 – 15) Invalid combinations 6 0110
7 0111
● It can be thought of as weighted code! 8 1000
9 1001
Example
(58)10 BCD?
58
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)
59
Excess-3 Code
Excess-3 = Binary + 3
Decimal Binary Excess 3 Can figure out the relation
0 0000 0011 between the codes of 0 and
9, 1 and 8, 2 and 7 …. ?
1 0001 0100
2 0010 0101 Complement Code!
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
60
8, 4, -2, -1 Code
61
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).
62
ASCII Table
63
ASCII Code
ASCII has some interesting properties:
● Digits 0 to 9 span Hexadecimal values 3016 to 3916
64
Unicode Code
Non-numeric
65
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
66
Error Detecting Codes
Good for checking odd number of errors
Example
67
Gray Code
None-numeric code Decimal Gray Binary
0 0000 0000
1 0001 0001
2 0011 0010
What is special about 3 0010 0011
4 0110 0100
gray code? 5 0111 0101
6 0101 0110
● One bit changes from 7 0100 0111
one code to the next 8 1100 1000
code 9 1101 1001
10 1111 1010
11 1110 1011
12 1010 1100
13 1011 1101
14 1001 1110
15 1000 1111
68
Gray Code
How to generate n binary gray Decimal BCD Gray
code? 0 0000 0000
● Replace each of the first n/2 1 0001 0001
numbers with a code consisting 2 0010 0011
of 0 followed by the even parity 3 0011 0010
of each bit of the binary code 4 0100 0110
word and the bit to its left 5 0101 1110
6 0110 1010
● Copy the sequence of numbers
7 0111 1011
formed and copy it in reverse
8 1000 1001
order with the leftmost bit
replaced by 1 9 1001 1000
69
Exercises
Suggested Problems (5th Edition)
1-1
1-2
1-3
1-5
1-6
1-7
1-15
1-18
1-21
1-29
71