C1 p2 Code Conversion

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

HCMC University of Technology and Education

Faculty of Electrical & Electronic Engineering

KỸ THUẬT SỐ

CHƯƠNG 1:
GIỚI THIỆU VÀ MÃ

Assoc. Prof. Nguyen Thanh Hai


1
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering Binary to Decimal Conversion

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

MSD: Most Significant Digit


Ex. 1: 110101012 =
= (1x 27) + (1x 26) + (0x25) + (1x24) + (0x23)
+ (1x22) + (0x 21 ) + (1x 20)
= 128 + 64 + 0x32 + 16 + 0x8 + 4 + 0x2 + 1
= 21310
2138= 2x82 1x81 +3x80=13910
21316= 2x162 1x161 +3x160=53110
2
21B16= 2x162 1x161 +11x160=53910
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering Binary to Decimal Conversion (Cont.)

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

Convert number 2510 :


25 LSB
= 12 + remainder of 1
2
EX. 3:
12
= 6 + remainder of 0
2 4510 =
6
= 3 + remainder of 0 =1 0 1 1 0 12
2
3
= 1 + remainder of 1
2
1
= 0 + remainder of 1 2138= 2x82 1x81 +3x80=13910
2
MSB 21316= 2x162 1x161 +3x160=53110
21B16= 2x162 1x161 +11x160=53910
2510 = 1 1 0 0 12

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:

0.010= 0x2-1 + 1x2-2 + 0x2-3


= 0 + 0.25 + 0=0.25 0.2510 = 0 1 02
= 0.012

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

100 111 0102

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

Ex. 10: 2AF16 =


= 2x(162) + 10x(161) + 15x(160)
= 512 + 160 + 15
= 68710

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

Hex to Binary Conversion

9F216= 9 F 2
EX. 13: 1AF16 =
= 1001 1111 0010
= 1001111100102

Binary to Hex Conversion


EX. 14:
11101001102 = 0011 1010 0110
110100110012 =
= 3 A 6
= 3A616

12
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering

Hex to Octal Conversion

B2F16 = 1011 0010 1111


EX. 15: 1BC16 =

= 101 100 101 111

= 5 4 5 78

BCD Code (Binary-Coded-Decimal Code)

8 7 4 (decimal) EX. 16: 19510 =

1000 0111 0100 (BCD)

13
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering

Comparison of BCD and Binary

It is important to realize that BCD is not another


number system like binary, decimal, and
hexadecimal.

13710 = 100010012 (binary)


13710 = 0001 0011 0111BCD (BCD)
number.

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

Parallel transmission between two


computers with 8 bits
20
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering Transmission between PC and Printer

Series transmission between two


computers 21
Assoc. Prof. Nguyen Thanh Hai
HCMC University of Technology and Education
Faculty of Electrical & Electronic Engineering

The End

22
Assoc. Prof. Nguyen Thanh Hai

You might also like