Chapter 1 Number System and Codes Decimal Binary Octal Hexadecimal Binary Coded Decimal (BCD)
Objectives
• At the end of this chapter, students should be able to:– Differentiate between decimal, binary, octal, hexadecimal and BCD. – Convert number between bases.
10/9/2012
RA/Sept2013-Jan2014
2
Types of Number Systems
Decimal
Hexa decimal
Number Systems
Binary
Octal
10/9/2012
RA/Sept2012-Jan2013
3
List of Numbers/Symbols
10/9/2012
Type
Base
Numbers/Symbols
Decimal
10
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Binary
2
0, 1
Octal
8
0, 1, 2, 3, 4, 5, 6, 7
Hexadecimal
16
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
RA/Sept2012-Jan2013
4
Common Number Systems
10/9/2012
Binary
Octal
Decimal
Hexadecimal
0
0
0
0
1
1
1
1
10
2
2
2
11
3
3
3
100
4
4
4
101
5
5
5
110
6
6
6
111
7
7
7
1000
10
8
8
1001
11
9
9
1010
12
10
A
1011
13
11
B
1100
14
12
C
1101
15
13
D
1110
16
14
E
1111
17RA/Sept2012-Jan201315
F
5
Conversion Among Bases
10/9/2012
RA/Sept2012-Jan2013
6
Decimal
Binary
Decimal - Binary Technique: – Divide the decimal number by 2, keep track of the remainder. – First remainder is the Least Significant Bit (LSB). Eg. 8710 = _________ 2 2 2 2 2 2 2 2
87 43 21 10 5 2 1
43 21 10 5 2 1 0
remainder 1 remainder 1 remainder 1 remainder 0 remainder 1 remainder 0 remainder 1
LSB (Least Significant Bit)(right-most bit)
MSB (Most Significant Bit)(left-most bit)
Therefore, 8710 = 10101112 Binary – Decimal Technique: – Multiply each hexadecimal number by 2n, where n is the weight of the bit. – The weight is the position of the bit, starting from 0 on the right. (LSB) – Then, sum the results. MSB LSB Description Eg. 10101112 = _________ 10 6 5 4 3 2 1 0 2 1
2 0
2 1
2 0
2 1
2 1
2 1
Bit Weights Binary Number
= 1*26 + 1*24 + 1*22 + 1*21 + 1*20 = 64 + 16 + 4 + 2 + 1 = 8710
10/9/2012
Therefore, 10101112 = 87RA/Sept2012-Jan2013 10
7
Decimal
Octal
Decimal - Octal Technique: – Divide the decimal number by 8, keep track of the remainder. – First remainder is the Least Significant bit (LSB). Eg. 26610 = _________ 8 8 266 8 33 8 4
33 4 0
remainder 2 remainder 1 remainder 4
LSB (Least Significant Bit)(right-most digit) MSB (Most Significant Bit)(left-most digit)
Therefore, 26610 = 4128 Octal – Decimal Technique: – Multiply each octal number by 8n, where n is the weight of the digit. – The weight is the position of the digit, starting from 0 on the right. (LSD) – Then, sum the results. MSD LSD Description Eg. 4128 = _________ 10 82 4
81 1
80 2
Bit Weights Octal Number
4128 = (4 x 82 ) + (1 x 81) + (2 x 80) = 256 + 8 + 2 = 26610
10/9/2012
Therefore, 4128RA/Sept2012-Jan2013 = 26610
8
Decimal
Hexadecimal
Decimal - Hexadecimal Technique: – Divide the decimal number by 16, keep track of the remainder. – First remainder is the Least Significant Digit (LSD). Eg. 42310 = _________ 16 16 423 16 26 16 0
26 1 0
remainder 7 remainder 10 remainder 1
LSD (Least Significant Digit)(right-most digit) MSD (Most Significant Digit)(left-most digit)
Therefore, 42310 = 1A716 Hexadecimal – Decimal Technique: – Multiply each hexadecimal number by 16n, where n is the weight of the digit. – The weight is the position of the digit, starting from 0 on the right. (LSD) – Then, sum the results. MSD LS Description Eg. 1A716 = _________ 10 162 1
Therefore, 1A716 = 42310 10/9/2012
= = =
161 A
D 160 7
(1 x 162 ) + 256 + 42310.
RA/Sept2012-Jan2013
Hex Digit Weights Hex Number (10 x 161) + (7 x 160) 160 + 7
9
Decimal
BCD
Decimal - BCD
Technique: Replace each decimal digit (0 – 9) with a 4-bit BCD code. Eg. 87410 = _________ BCD MSD 8 1000
7 0111
LSD
Description
4 0100
Decimal Number BCD Code
Therefore, 87410 = 100001110100BCD BCD – Decimal
Technique: Replace each 4 bits BCD digit with a decimal number. Eg. 0001100101111000BCD = _________ 10 MSD 0001 1
1001 9
0111 7
LSD
Description
1000 8
BCD Code Decimal Number
Decimal
BCD
0
0000
1
0001
2
0010
3
0011
4
0100
5
0101
6
0110
7
0111
8
1000
9
1001
Therefore, 0001100101111000BCD = 197810 10/9/2012
RA/Sept2012-Jan2013
10
Binary
Octal
Binary - Octal
Technique: - Group bits in threes, starting from right (LSB). - Then, convert to octal. MSD
Eg. 110101102 = _________ 8
011 3
LSD Description 010 2
110 6
Binary number Octal number
Therefore, 110101102 = 3268 Octal – Binary
Technique: - Replace each octal digit with 3-bit binary number. MSD
Eg. 4728 = _________ 2
4 100
LSD Description 7 111
2 010
Octal number Binary number
Therefore, 4728 = 1001110102 10/9/2012
RA/Sept2012-Jan2013
11
Binary
Hexadecimal
Binary - Hexadecimal
Technique: - Group bits in fours, starting from right (LSB). - Then, convert to hexadecimal. MSD
Eg. 101111110101102 = _________ 16
0010 2
1111 F
1101 D
LSD
Description
0110 6
Binary Number Hex Number
Therefore, 101111110101102 = 2FD616 Hexadecimal – Binary
Technique: - Replace each octal digit with 4-bit binary number. MSD
Eg. 1A716 = _________ 2
1 0001
LSD A 1010
Description
7 Hex Number 0110 Binary Number
Therefore, 1A716 = 0001101001112 10/9/2012
RA/Sept2012-Jan2013
12
Octal
Hexadecimal
Octal - Hexadecimal
Technique: - Use binary as an intermediary. 1 Eg. 174.368 = _________ 16
001
7
4
.
3
111
100
.
011
C
.
7
7
Description Octal number
6
110 Binary number 8 Hexadecimal number
Therefore, 174.368 = 7C.7816 Hexadecimal - Octal
Technique: - Use binary as an intermediary. Eg. 7C.7816 = _________ 8
Therefore, 7C.7816 = 174.368
10/9/2012
7
C
.
7
0111
1100
.
0111
4
.
3
1
RA/Sept2012-Jan2013
7
8
Description Hexadecimal number
1000 Binary number 6
0 Octal number
13
Base Conversion with the Remainder Method Decimal - Binary
Eg. Convert 23.37510 to base 2. Technique: 1.
10/9/2012
Start by converting the integer portion:
RA/Sept2012-Jan2013
14
Base Conversion with the Multiplication Method 2. Then, convert the fraction:
(Take 0)
(Take 1)
(Take 1)
Putting it all together, 23.37510 = 10111.0112
10/9/2012
RA/Sept2012-Jan2013
15
Fractions Binary - Decimal
Technique: – Multiply each binary number by 2-n, where -n is the weight of the bit for fraction starting from left to right. . – Then, sum the results. Eg. 1010.012 = _________ 10 1010.012 = 1 x 23 + 0 x 22 + 1 x 21 + 0 x 20 + 0 x 2-1 + 1 x 2-2 = 10 + 0.25 = 10.25 10 Therefore, 1010.012 = 10.2510
10/9/2012
RA/Sept2012-Jan2013
16
Fractions Octal – Decimal
Technique: – Multiply each octal number by 8-n, where -n is the weight of the bit for fraction starting from left to right. . – Then, sum the results. Eg. 46.38 = _________ 10 46.38 = 4 x 81 + 6 x 80 + 3 x 8-1 = 38 + 0.375 = 38.375 10 Therefore, 46.38 = 38.37510
10/9/2012
RA/Sept2012-Jan2013
17
Fractions Hexadecimal - Decimal
Technique: – Multiply each hexadecimal number by 16-n, where -n is the weight of the bit for fraction starting from left to right. . – Then, sum the results. Eg. A7.0F16 = _________ 10 A7.0F16 = 10 x 161 + 7 x 160 + 0 x 16-1 + 15 x 16-2 = 167 + 0.059 = 167.059 10 Therefore, A7.0F16 = 167.05910
10/9/2012
RA/Sept2012-Jan2013
18
BCD
Binary,Octal, Hexadecimal
BCD – Binary, Octal, Hexadecimal
Technique: – First, convert the BCD number to decimal. – Then, convert the decimal number to the indicated base . Eg. 01011000BCD = _________ 8 01011000BCD = 5810 = 728 Therefore, 01011000BCD = 728 Binary, Octal, Hexadecimal - BCD
Technique: – First, convert the indicated base to decimal. – Then, convert the decimal number to BCD. Eg. E216 = _________ BCD E216 = 22610 = 001000100110BCD Therefore, E2 16 = 001000100110BCD 10/9/2012
RA/Sept2012-Jan2013
19
Test Yourself 1. Convert the following number to the indicated base/code. No. 1.
Binary
Octal
Decimal
Hexadecimal
10101112
2.
BACA16
3. 4. 5.
BCD
10010011BCD 3248 69410
2. Convert the following number to the indicated base/code. a) 11101.112 to decimal. b) FED.4716 to octal. c) 01101001BCD to binary. d) 7548 to BCD. e) 152.2510 to hexadecimal.
10/9/2012
RA/Sept2012-Jan2013
20