0% found this document useful (0 votes)
2 views

01 - Binary Systems

Uploaded by

kamhadido
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

01 - Binary Systems

Uploaded by

kamhadido
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

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.

★ 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?
8
Digital Systems & Computers

Sampling (discrete x-axis)

Quantization (discrete y-axis)


9
Digital System Example
Digital Computers

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

Inputs: Count Up, Reset


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

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

Cell phones Dishwashers


Automobiles Flat Panel TVs
Video games Global Positioning Systems
Copiers
12
The Big Picture

Digital Logic Computer Organization and


Architecture I
Electronics I and II
Build Processing Units, ALUs, instructions,
understand floating point arithmetic, etc.

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

● Disk 🡺 Magnetic Field Direction

● CD 🡺 Surface Pits/Light

● Dynamic RAM 🡺 Electrical Charge stored in capacitors

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)

Quick transition, OK!

Slow transition, BAD!

No guarantees what
the output might be!
18
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
19
Numbering Systems
Number Systems
★ Base (also called radix) = B (or r)
★ Formal Notation Base point

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

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


★ Example
● (123.2)5 = ( ? )10

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

● 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
24
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
25
Examples
★ (10110)2 = ( )10

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

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


★ Magnitude 2 1 0 -1 -2
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

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

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


★ Magnitude 2 1 0 -1 -2
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

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

6 26=64 30 230=1G Giga

7 27=128 40 240=1T Tera


30
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
31
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
32
Examples
★ If (BEE)r = (2699)10 , then what is r?

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

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


45
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
( 1 0 1 1 0 . 0 1 )2 8 1000
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)
46
Examples
★ (7563 . 1102)8 = ( )2

★ ( 011 011 110 101 100 . 010 11 )2 = ( )8

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

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)


49
Examples
★ (6503 . 21)8 = ( )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)

★ 1310 ⇔ 0001|0011 (This is coding)

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

● 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

63
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/

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

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

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

● The left most bit is set to 0 3 0011 0010


4 0100 0110
● For the remaining bits, calculate
5 0101 1110
the even parity of every two
6 0110 1010
consecutive bits in the binary
code 7 0111 1011
8 1000 1001

Binary = 0010 Gray = 0 9 1001 1000

Binary = 0010 Gray = 00 ● For the remaining n/2 code,


Binary = 0010 Gray = 001 replace the MSB of the first n/2
codes with 1 and copy them in
Binary = 0010 Gray = 0011
reverse order
● Note that n must be even.
68
Exercises
Suggested Problems (5th Edition)
★ 1-1
★ 1-3
★ 1-5
★ 1-6
★ 1-7
★ 1-15
★ 1-29

70

You might also like