Lecture: DIGITAL SYSTEMS Nguyen Thanh Hai, PhD Chapter 2: Number Systems and Codes Number Systems and Codes University of Technical Education Faculty of Electrical & Electronic Engineeri
Trang 1Lecture:
DIGITAL SYSTEMS
Nguyen Thanh Hai, PhD
Chapter 2:
Number Systems and Codes
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
2
2.1 Binary to Decimal Conversions 2.2 Decimal to Binary Conversions 2.3 Octal Number System
2.4 Hexadecimal Number System 2.5 BCD Code
2.6 Gray code
2.7 Putting It All Together
2.8 Applications
Trang 2Basic Concepts
Nguyen Thanh Hai, PhD
Bit: a binary digit composed of 0 or 1
Byte: composed of 8 bits
Word: composed of 4 bytes and equal to 32 bits
Base 2 (binary digits): numbers composed of bits
Base 10 (decimal digit): numbers composed of the digits from 0-9 Base 16 (hexa digit or hexadecimal): numbers composed of the digits from 0-9 and letters A-F
Base 8 (octal digit): numbers composed of the digits from 0-7
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
4
Binary digits:
MSB (Most Significant Bit)
LSB (Least Significant Bit)
bit
1 Byte = 8 bits
bit bit
Kb
Binary system: 0 and 1
Binary digits
Trang 3Ex 1: 11010101 2 =
= (1x 2 7 ) + (1x 2 6 ) + (0x2 5 ) + (1x2 4 ) + (0x2 3 ) + (1x2 2 ) + (0x 2 1 ) + (1x 2 0 )
= 128 + 64 + 0x32 + 16 + 0x8 + 4 + 0x2 + 1
= 213 10
2.1 Binary to Decimal Conversion
Binary digits
Weights
Nguyen Thanh Hai, PhD
MSD: Most Significant Digit
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
6
Ex 2: 1101.101 2 =
= (1x 2 3 ) + (1x 2 2 ) + (0x2 1 ) + (1x2 0 ) + (1x2 -1 ) + (0x2 -2 ) + (1x 2 -3 )
= 8 + 4 + 0 + 1 + 0.5 + 0 + 0.125
= 13.625 10
point
LSB
Binary digits
Weights
Nguyen Thanh Hai, PhD
2.1 Binary to Decimal Conversion (Cont.)
Decimal point
Trang 425
2 = 12 + remainder of 1
12
2 = 6 + remainder of 0
6
2 = 3 + remainder of 0
3
2 = 1 + remainder of 1
1
2 = 0 + remainder of 1
2510= 1 1 0 0 12
LSB
MSB
EX 3:
45 10 =
= 1 0 1 1 0 1 2
Convert number 25:
2.2 Decimal to Binary Conversion
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
8
0.25x2 = 0.50 + remainder of 0
0.25 10 = 0 1 0 2
= 0.010 2
MSB
LSB
Convert number 0.25:
0.5x2 = 1.0 + remainder of 1
0x2 = 0 + remainder of 0
0.010= 0x2 -1 + 1x2 -2 + 0x2 -3
= 0 + 0.25 + 0=0.25
Notice:
2.2 Decimal to Binary Conversion
Trang 5Ex 4: 372 8 =
= 3x(8 2 ) + 7x(8 1 ) + 2x(8 0 )
= 3x64 + 7x8 + 2x1
= 250 10
2.3 Octal Number System
Nguyen Thanh Hai, PhD
Ex 5: 24.6 8 =
= 2x(8 1 ) + 4x(8 0 ) + 6x(8 -1 )
= 2x8 + 4x1 + 6/8
= 20.75 10
Octal to Decimal Conversion
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
10
Decimal to Octal Conversion
266
8 = 33 + remainder of 2
33
8 = 4 + remainder of 1
4
8 = 0 + remainder of 4
26610= 4 1 28
LSD
MSD
EX 6: 14510 =
145
8 = 18 + remainder of 1
18
8 = 2 + remainder of 2 2
8 = 0 + remainder of 2
14510= 2 2 18
LSD
MSD
Convert number 266:
Trang 6Ý nghĩa một số nhị phân: 0 1 2 3 4 5 6 7
000 001 010 011 100 101 110 111
Octal to Binary Conversion
Octal digit
Binary
equivalent
Nguyen Thanh Hai, PhD
Ex 7:
472 8 =
4 7 2
100 111 010
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
12
000 001 010 011 100 101 110 111
Binary to Octal Conversion
Octal
equivalent
Binary digit
Ex 8:
111 101 110
7 5 6 8
Trang 7Ex 9:
356 16 =
= 3x(16 2 ) + 5x(16 1 ) + 6x(16 0 )
= 3x256 + 5x15 + 6x1
= 768 + 80 + 6
= 854 10
2.4 Hexadecimal Number System
Nguyen Thanh Hai, PhD
Ex 10: 2AF 16 =
= 2x(16 2 ) + 10x(16 1 ) + 15x(16 0 )
= 512 + 160 + 15
= 687 10
Ex 11:
2B.E 16 =
= 2x(16 1 ) + 11x(16 0 ) + 14x(16 -1 )
= 32 + 11 + 0.875
= 43.875 10
Hex to Decimal Conversion
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
14
Decimal to Hex Conversion
423
16 = 26 + remainder of 7
26
16 = 1 + remainder of 10
1
16 = 0 + remainder of 1
42310= 1 A 716
LSD
MSD
EX 12: 14510 = 145
16 = 9 + remainder of 1
9
16 = 0 + remainder of 9
14510= 9 116
LSD MSD
Convert number 423:
Trang 8Hex to Binary Conversion
Nguyen Thanh Hai, PhD
9F2 16 = 9 F 2
= 1001 1111 0010
= 100111110010 2
1110100110 2 = 0011 1010 0110
= 3 A 6
= 3A6 16
Binary to Hex Conversion
EX 13: 1AF 16 =
EX 14:
11010011001 2 =
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
16
Hex to Octal Conversion
B2F16 = 1011 0010 1111
= 101 100 101 111
= 5 4 5 78
2.5 BCD Code ( Binary-Coded-Decimal Code)
8 7 4 (decimal)
1000 0111 0100 (BCD)
EX 15: 1BC16 =
EX 16: 195BCD =
Trang 9• Comparison of BCD and Binary
It is important to realize that BCD is not another
number system like binary, decimal, and
hexadecimal
17
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
2.6 The Gray Code
The unique aspect of the Gray code is that only one bit ever changes between two successive numbers in the sequence.
18
Trang 10Converting binary to Gray
19
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
Converting Gray to binary.
20
Trang 11Decimal Binary Octal Hex BCD Gray
2.7 Putting It All Together
Nguyen Thanh Hai, PhD
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
22
Example 1:
Example 2:
Solution:
1 Convert to decimal
2 11000 2
3 2 12 - 1
Trang 12Application 1:
A typical CD-ROM can store 650 megabytes of digital data Since 1 mega = 2 20 , how many bits of data can a CD-ROM hold?
Solution:
650 x 2 20 x 8 = 5,452,595,200 bits
Nguyen Thanh Hai, PhD
2.8 Applications
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
24
Application 2:
A small process-control computer
uses octal codes to represent its
12-bit memory addresses.
a How many octal digits are
required?
b What is the range of addresses
in octal?
c How many memory locations are
there?
2.8 Applications
Solution:
a 12/3 = 4
b 0000 8 to 7777 8
c With 4 octal digit,
8 4 = 4096
Trang 13Nguyen Thanh Hai, PhD
Application 3:
A typical PC uses a 20-bit
address code for its memory
locations.
a How many hex digits are
needed to represent a
memory address?
b What is the range of
addresses?
c What is the total number of
memory locations?
c With 5 hex digits, 16 5 =
1,048,576
b 00000 16 to FFFFF 16
Solution:
a 20/4 = 5 hex digits
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
26
Application 4:
Most calculators use BCD to
store the decimal values as
they are entered into the
keyboard and to drive the digit
displays.
a If a calculator is designed to
handle 8-digit decimal
numbers, how many bits does
this require?
b What bits are stored when the
number 375 is entered into the
calculators?
b 375 10 converts to
0011 0111 0101 (BCD) Solution:
a 8 x 4 = 32 bits
Trang 14Nguyen Thanh Hai, PhD
Open and closed
switches
representing 0 and
1, respectively of holes in paper tape Absence or presence
representing 0 and 1, respectively
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
28
Typical voltage
assignments in digital
system
Typical digital system timing diagram
Trang 15Nguyen Thanh Hai, PhD
A digital circuit
responds to an
input’s binary
level (0 or 1) and
not to its actual
voltage
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
30
Application 5:
Solution:
1 False
2 Yes
3 Logic
4 Timing diagram
Trang 16Nguyen Thanh Hai, PhD
Parallel transmission between two
computers with 8 bits
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
32
Series transmission between two
computers
Trang 17Nguyen Thanh Hai, PhD
Functional Diagram
of a digital
computer
Comparison between non-memory and memory operation
Number Systems and Codes
University of Technical Education
Faculty of Electrical & Electronic Engineering
34
-Take a look Examples
- Answer Review questions at pages 20
- Homework at pages 21-22
[1] Ronald J Tocci, Neal S Widmer, Digital
Systems: Principles and Applications, 8th
Ed Prentice Hall, 2007.
[2] N D Phu, N T Duy Giao Trinh: Ky
Thuat So, 2013.
Trang 18Nguyen Thanh Hai, PhD
The End