You are on page 1of 71

Digital Logic

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.

Digital Electronics Computer Organization and


Architecture II

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.

 Use discrete/digital representation for information


● Finite number of points
● Finite number of values can be assigned to these points
 Why can’t we just use the analogue representation? Analogue
quantities have infinite points and possible values for these points.
● Impossible to store and process!
 How to get discrete representation?
10
Digital Systems & Computers

14
12
10
Value

8
6
4
2
0
0 2 4 6 8 10 12
Time

Sampling (discrete x-axis)

Quantization (discrete y-axis)


11
Digital System Example
Digital Computers

Memory

Control
CPU unit Datapath

Inputs Outputs

keyboard, mouse, wireless,


Input/Output LCD screen, wireless,

microphone speakers

12
Digital System Example
A Digital Counter (e. g., odometer):

Count Up

Reset 0 0 1 3 5 64

Inputs: Count Up, Reset


Outputs: Visual Display
State: "Value" of stored digits

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

Cell phones Dishwashers


Automobiles Flat Panel TVs
Video games Global Positioning Systems
Copiers
14
Digital Logic
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)

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

● Disk  Magnetic Field Direction

● CD  Surface Pits/Light

● Dynamic RAM  Electrical Charge stored in


capacitors

18
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)


Quick transition, OK!

Slow transition, BAD!

No guarantees what
the output might be!
19
Digital Logic
 Representation using voltage

 The first digital circuits operated at a range of 0 to 5 Volts (TTL


Logic)
● Large and SAFE threshold space
 Problem: power increases with the SQUARE of voltage! A higher
system operating voltage means
● more power consumed
● More heat generated
● therefore, cooling problems
Solution  Decrease voltage range, but new issues? Narrow safe space
20
Numbering Systems
Number Systems
 Base (also called radix) = B (or r)
 Formal Notation
( 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 … …
22
Number Systems
 Magnitude in decimal
● Sum of “Digit x Weight”

dN-1*rN-1+…+ d1*r1+d0*r0+d-1*r-1+ … +d-M*r-M

 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

● Integer & fraction 5 1 2 7 4


 Digit Weight 100 10 1 0.1 0.01
● Weight = (Base) Position
 Magnitude
500 10 2 0.7 0.04
● Sum of “Digit x Weight”
d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2
 Formal Notation
(512.74)10
25
Binary Number System
 Base = 2
● 2 digits { 0, 1 }, called binary digits or “bits”

 Weights 4 2 1 1/2 1/4

● Weight = (Base) Position 1 0 1 0 1


2 1 0 -1 -2
 Magnitude
1 *22+0 *21+1 *20+0 *2-1+1 *2-2
● Sum of “Bit x Weight”
=(5.25)10
 Formal Notation
(101.01)2
 Groups of bits 4 bits = Nibble
1011
8 bits = Byte
11000101
26
Examples

 (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

● Weight = (Base) Position 5 1 2 7 4


2 1 0 -1 -2
 Magnitude
5 *82+1 *81+2 *80+7 *8-1+4 *8-2
● Sum of “Digit x Weight”
=(330.9375)10
 Formal Notation
(512.74)8

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

● Weight = (Base) Position 1 E 5 7 A


2 1 0 -1 -2
 Magnitude
1 *162+14 *161+5 *160+7 *16-1+10 *16-2
● Sum of “Digit x Weight”
=(485.4765625)10
 Formal Notation
(1E5.7A)16

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

6 26=64 30 230=1G Giga

7 27=128 40 240=1T Tera


31
Decimal, Binary, Octal and Hexadecimal

Decimal Binary Octal Hex


00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
32
Decimal, Binary, Octal and Hexadecimal
Decimal Binary Octal Hex
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 10000 20 10
17 10001 21 11
33
Examples

 If (BEE)r = (2699)10 , then what is r?

 (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

Works both ways (Binary to Octal & Octal to Binary)


46
Binary − Hexadecimal Conversion
 16 = 24 Hex Binary
0 0000
 Each group of 4 bits represents 1
2
0001
0010
a hexadecimal digit 3 0011
4 0100
5 0101
Assume Zeros 6 0110
Example:
7 0111
8 1000
( 1 0 1 1 0 . 0 1 )2 9 1001
A 1010
B 1011
C 1100
D 1101
(1 6 . 4 )16 E 1110
F 1111
Works both ways (Binary to Hex & Hex to Binary)
47
Examples

 (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

Assume Zeros Assume Zeros

( 0 1 0 1 1 0 . 0 1 0 )2

(1 6 . 4 )16

Works both ways (Octal to Hex & Hex to Octal)


50
Examples

 (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)

 1310  0001|0011 (This is coding)

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

 Binary value = 8B3+ 4B2 – 2B1 – B0


Decimal Binary 8, 4, -2, -1 Can you figure out the
0 0000 0000 relation between the codes
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

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

● Upper case A-Z span 4116 to 5A16

● Lower case a-z span 6116 to 7A16

● Lower to upper case translation (and vice versa) occurs by flipping


bit number 5

64
Unicode Code
 Non-numeric

 Extends ASCII to universal characters codes

 It uses 16 bits (i.e. 65,536 codes) for encoding characters in


world languages and it is available in many modern
applications

 For more information, visit https://home.unicode.org/

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

4-bit Example 7-bit Example

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

 Note that n must be even.

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

You might also like