Professional Documents
Culture Documents
C1 p2 Code Conversion
C1 p2 Code Conversion
C1 p2 Code Conversion
KỸ THUẬT SỐ
CHƯƠNG 1:
GIỚI THIỆU VÀ MÃ
Binary digits
1 1 0 1 0 1 0 1
27 26 25 24 23 22 21 20
Weights
=128 =64 =32 =16 =8 =4 =2 =1
MSD LSD
Binary digits
1 1 0 1 . 1 0 1
23 22 21 20 2-1 2-2 2-3
Weights
=8 =4 =2 =1 =1/2 =1/4 =1/8
MSB Binary LSB
point
Ex. 2: 1101.1012 =
= (1x 23) + (1x 22) + (0x21) + (1x20) + (1x2-1)
+ (0x2-2) + (1x 2-3 )
= 8 + 4 + 0 + 1 + 0.5 + 0 + 0.125
= 13.62510
Decimal point
3
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Decimal to Binary Conversion
Faculty of Electrical & Electronic Engineering
4
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
Decimal to Binary Conversion
Convert number 0.25:
MSB
0.25x2 = 0.50 + remainder of 0
0.5x2 = 0 + remainder of 1
0x2 = 0 + remainder of 0
LSB
Notice:
5
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
Octal Number System
Octal to Decimal Conversion
Ex. 4: 3728 =
= 3x(82) + 7x(81) + 2x(80)
= 3x64 + 7x8 + 2x1
= 25010
Ex. 5: 24.68 =
= 2x(81) + 4x(80) + 6x(8-1)
= 2x8 + 4x1 + 6/8
= 20.7510
6
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering Decimal to Octal Conversion
Convert number 266:
EX. 6: 14510 =
266 LSD
= 33 + remainder of 2 145 LSD
8 = 18 + remainder of 1
8
33
= 4 + remainder of 1 18
8 = 2 + remainder of 2
MSD 8
4
= 0 + remainder of 4 2 MSD
8 = 0 + remainder of 2
8
26610 = 4 1 28
14510 = 2 2 18
7
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering Octal to Binary Conversion
Octal digit
0 một1số nhị phân:
Ý nghĩa 2 3 4 5 6 7
Binary
000 001 010 011 100 101 110 111
equivalent
Ex. 7:
4728=
4 7 2
8
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
Binary to Octal Conversion
Octal
equivalent
000 001 010 011 100 101 110 111
Binary digit
0 1 2 3 4 5 6 7
Ex. 8:
111 101 110
7 5 68
9
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering Hex to Decimal Conversion
Ex. 9:
Ex. 11:
35616 =
2B.E16 =
= 3x(162) + 5x(161) + 6x(160)
= 2x(161) + 11x(160) + 14x(16-1)
= 3x256 + 5x16 + 6x1
= 32 + 11 + 0.875
= 768 + 80 + 6
= 43.87510
= 85410
10
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
Decimal to Hex Conversion
Convert number 423:
423 LSD
= 26 + remainder of 7 EX. 12: 14510 =
16
145 LSD
26 = 9 + remainder of 1
= 1 + remainder of 10 16
16
MSD
1 MSD 9
= 0 + remainder of 1 = 0 + remainder of 9
16 16
14510 = 9 116
42310 = 1 A 716
11
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
9F216= 9 F 2
EX. 13: 1AF16 =
= 1001 1111 0010
= 1001111100102
12
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
= 5 4 5 78
13
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
14
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
Example 1:
Example 2:
Solution:
1. Convert to decimal
2. 110002
15
Assoc. Prof. Nguyen Thanh Hai
3. 212 - 1
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
Applications
Application 1:
A typical CD-ROM can store 650 megabytes of digital
data. Since 1 mega = 220, how many bits of data can a
CD-ROM hold?
Solution:
650 x 220 x 8 = 5,452,595,200 bits
16
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering Applications
Application 2:
A small process-control computer
Solution:
uses octal codes to represent its
12-bit memory addresses.
a. How many octal digits are a. 12/3 = 4
required?
b. What is the range of addresses b. 00008 to 77778
in octal?
c. How many memory locations are c. With 4 octal digit,
there? 84= 4096
17
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
Application 3:
A typical PC uses a 20-bit
address code for its memory
locations. Solution:
a. How many hex digits are a. 20/4 = 5 hex digits
needed to represent a
memory address?
b. What is the range of b. 0000016 to FFFFF16
addresses?
c. What is the total number of c. With 5 hex digits, 165=
memory locations? 1,048,576
18
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering
Application 4:
Most calculators use BCD to
store the decimal values as
they are entered into the
Solution:
keyboard and to drive the digit
displays.
a. If a calculator is designed to a. 8 x 4 = 32 bits
handle 8-digit decimal
numbers, how many bits does
this require?
b. What bits are stored when the b. 37510 converts to
number 375 is entered into the 0011 0111 0101 (BCD)
calculators?
19
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering Transmission between PC and Printer
The End
22
Assoc. Prof. Nguyen Thanh Hai