Upload
vuongquynh
View
215
Download
0
Embed Size (px)
Citation preview
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 1
Chapter 2
NUMBER SYSTEMS
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 2
Lesson 2
Hexadecimal, BCD and Octal Number Systems
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 3
Outline•• Hexadecimal systemHexadecimal system• 2 or 4 or 8 hex-digit representation• BCD system• 2 or 4 BCD digit representation• Octal system• Conversion
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 4
hexhex--digitsdigits
�� Let yLet ypp = digit at = digit at ppthth place place of the place place of the digit when p = 0, 1, 2, digit when p = 0, 1, 2, ……., (pmax ., (pmax –– 3), 3), (pmax (pmax –– 2) or (pmax 2) or (pmax –– 1), from right to 1), from right to leftleft
�� Hexadecimal hexHexadecimal hex--digit written as y = F digit written as y = F or E or D or C or B or A or 9 or 8 or 7 or E or D or C or B or A or 9 or 8 or 7 or 6 or 5 or 4 or 3 or 2 or 1 or 0 and is or 6 or 5 or 4 or 3 or 2 or 1 or 0 and is used a four bit binary number 1111, used a four bit binary number 1111, 1110, ...., 0001, 0000, respectively1110, ...., 0001, 0000, respectively
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 5
yypmax pmax ––1 1 ×××××××× ww00pmax pmax ––1 1 + y+ ypmax pmax ––22 ××××××××
ww00pmax pmax ––2 2 ×××××××× yypmax pmax ––33 x wx w00
pmax pmax ––3 3
++………………. + . + yy22 ×××××××× ww002 2 + y+ y11 ×××××××× ww00
1 1
++ yy00 ×××××××× ww0000 , , …………………………. (1). (1)
Formula N = sum of the yp (Base)p
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 6
Assume place value and base (weight)Assume place value and base (weight)
�� p = place of the hexp = place of the hex--digit = 0, 1, 2, digit = 0, 1, 2, ……., (pmax ., (pmax –– 3), (pmax 3), (pmax –– 2) or 2) or (pmax (pmax –– 1), from right to left1), from right to left
�� pmax = maximum the number of pmax = maximum the number of places used in the representation places used in the representation andand
�� w0 = base (basic weight) = 16w0 = base (basic weight) = 16
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 7
99dd = 09= 09hh 0000000010011001bb = = 0 = = 0 ×××××××× ww00
1 1 ++ 9 9 ×××××××× ww000 0
………………………………………………………………………… (2) (2) ww0 0 = 16= 16
A Formula
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 8
1212dd = 0C= 0Chh = = 0000000011001100bb = = 0 0 ×××××××× ww00
1 1 ++ 12 12 ×××××××× ww000 0
………………………………………………………………………… (3) (3) CChh= 12= 12dd; w; w0 0 = 16= 16
A Formula
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 9
100100dd = 64= 64hh = = 0110011001000100bb = = 6 6 ×××××××× ww00
1 1 + + 4 4 ×××××××× ww0000
……………………………… (4) (4)
ww0 0 = 16= 16
A Formula
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 10
10241024dd = 0400= 0400hh = = 00000000010001000000000000000000bb = 0 = 0 ××××××××
ww003 3 + 4 + 4 ×××××××× ww00
2 2 ++ 0 0 ×××××××× ww001 1 + +
0 0 ×××××××× ww0000 ………………………………
(5) (5)
ww0 0 = 16= 16
A Formula
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 11
Outline• Hexadecimal system•• 2 or 4 or 8 hex2 or 4 or 8 hex--digit representationdigit representation• BCD system• 2 or 4 BCD digit representation• Octal system• Conversion
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 12
2-hex-digit Hexadecimal representation
• 3d = 03h = 0011 b
• 15d = 0Fh = 1111 b
• 127d = 7Fh = 01111111 b
• 254d = FEh = 11111110 b• One nibble and a nibble is between 0 and F and
has four bits
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 13
4-hex-digit Hexadecimal representation
• 3d = 0003h = 0000000000000011 b
• 127d = 007Fh = 0000000001111111 b
• 254d = 00FEh = 0000000011111110 b
• 511d = 01FFh = 0000000111111111 b
• 1535d = 05FFh = 0000010111111111 b
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 14
Important Point to Remember
• A hexadecimal number is chosen as two-hex-digit number in case its decimal value lies between 0 and 255. [It means 0 and (16)2 – 1]
• A hexadecimal number is chosen as one-hex-digit number in case its decimal value lies between 0 and 15. [It means 0 and (16)1 – 1]
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 15
Important Point to Remember
• A hexadecimal number is chosen as eight-hex-digit number in case its decimal value lies between 0 and (65536*65536 – 1). [It means 0 and (16)8 – 1]
• A hexadecimal number is chosen as four-hex-digit number in case its decimal value lies between 0 and 65535. [It means 0 and (16)4 – 1]
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 16
Outline• Hexadecimal system• 2 or 4 or 8 hex-digit representation•• BCD systemBCD system• 2 or 4 BCD digit representation• Octal system• Conversion
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 17
BCD [Binary coded decimal digits]BCD [Binary coded decimal digits]
�� Let yLet ypp = digit at = digit at ppthth place place of the place place of the digit when p = 0, 1, 2, digit when p = 0, 1, 2, ……., (pmax ., (pmax –– 3), 3), (pmax (pmax –– 2) or (pmax 2) or (pmax –– 1), from right to 1), from right to leftleft
�� BCD decimal system BCDBCD decimal system BCD--digit y = 9 digit y = 9 or 8 or 7 or 6 or 5 or 4 or 3 or 2 or 1 or 0 or 8 or 7 or 6 or 5 or 4 or 3 or 2 or 1 or 0 and codes as 1001, 1000, 0111, ..., 0001 and codes as 1001, 1000, 0111, ..., 0001 or 0000or 0000
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 18
yypmax pmax ––1 1 ×××××××× ww00pmax pmax ––1 1 + y+ ypmax pmax ––22 ××××××××
ww00pmax pmax ––2 2 ×××××××× yypmax pmax ––33 x wx w00
pmax pmax ––3 3
++………………. + . + yy22 ×××××××× ww002 2 + y+ y11 ×××××××× ww00
1 1
++ yy00 ×××××××× ww0000 , , …………………………. (6). (6)
Formula N = sum of the yp (Base)p
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 19
Assume place value and base (weight)Assume place value and base (weight)
�� p = place of the digit = 0, 1, 2, p = place of the digit = 0, 1, 2, ……., ., (pmax (pmax –– 3), (pmax 3), (pmax –– 2) or (pmax 2) or (pmax ––1), from right to left1), from right to left
�� pmax = maximum the number of pmax = maximum the number of places used in the representation places used in the representation andand
�� w0 = base (basic weight) = 10w0 = base (basic weight) = 10
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 20
0909dd = 09= 09hh saves as saves as 0000000010011001bcdbcd = 0 = 0 ×××××××× ww00
1 1 ++ 9 9 ×××××××× ww00
0 0
………………………………………………………………………… (7) (7) ww0 0 = 10= 10
A Formula
BCD number
BCD number
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 21
1212dd = 0C= 0Ch h saves assaves as0001000100100010bcdbcd == 1 1 ×××××××× ww00
1 1 ++ 12 12 ×××××××× ww00
0 0
………………………………………………………………………… (8) (8) CChh= 12= 12dd; w; w0 0 = 10= 10
A Formula
BCD number
BCD number
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 22
01000100dd = 0064= 0064hh saves saves as as 00010001000000000000000001000100bcdbcd = = 1 1 ×××××××× ww00
2 2 + 0 + 0 ×××××××× ww001 1 + + 0 0 ×××××××× ww00
00
……………………………… (9) (9)
ww0 0 = 10= 10
A Formula4 BCD numbers
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 23
10241024dd = 0400= 0400hh saves as saves as 00010001000000000010001001000100bcd=bcd=1 1 ×××××××× ww00
3 3 + 0 + 0 ×××××××× ww002 2 ++ 2 2 ××××××××
ww001 1 + + 4 4 ×××××××× ww00
00
……………………………… (10) (10)
ww0 0 = 10= 10
A Formula
4 BCD numbers
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 24
Outline• Hexadecimal system• 2 or 4 or 8 hex-digit representation• BCD system•• 2 or 4 BCD digit representation2 or 4 BCD digit representation• Octal system• Conversion
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 25
2-BCD digit BCD representation
• 03d = 03h = 00000011 bcd
• 15d = 0Fh = 00010101 bcd• One nibble and a nibble is between 0 and 9 has
four bits [Note: Difference with hexadecimal
number binary -representation 00001111b]
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 26
4-BCD digit BCD representation
• 0511d= 01FFh = 0000010100010001 bcd
• 1535d= 05FFh = 0001010100110101bcd
4 BCD numbers
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 27
Important Point to Remember
• A BCD number is chosen as two-BCD digit number in case its decimal value lies between 0 and 99. [It means 0 and (10)2 – 1] and stores as 8-bits (two nibbles, each nibble for each BCD digit)
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 28
Important Point to Remember• A BCD number is chosen as eight-BCD
digit number in case its decimal value lies between 0 and 99999999. [It means 0 and (10)8 – 1] and stores as 32-bits (8 nibbles)
• A BCD number is chosen as four-BCD digit number in case its decimal value lies between 0 and 9999, [It means 0 and (10)4 –1] and stores as 16-bits (four nibbles)
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 29
Outline• Hexadecimal system• 2 or 4 or 8 hex-digit representation• BCD system• 2 or 4 BCD digit representation•• Octal systemOctal system• Conversion
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 30
OctalOctal--digitsdigits
�� Let yLet ypp = octal= octal--digit at digit at ppthth place place place place of the digit when p = 0, 1, 2, of the digit when p = 0, 1, 2, ……., (pmax ., (pmax ––3), (pmax 3), (pmax –– 2) or (pmax 2) or (pmax –– 1), from right 1), from right to leftto left
�� OctalOctal--digit y = 7 or 6 or 5 or 4 or 3 or digit y = 7 or 6 or 5 or 4 or 3 or 2 or 1 or 0 2 or 1 or 0
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 31
yypmax pmax ––1 1 ×××××××× ww00pmax pmax ––1 1 + y+ ypmax pmax ––22 ××××××××
ww00pmax pmax ––2 2 ×××××××× yypmax pmax ––33 x wx w00
pmax pmax ––3 3
++………………. + . + yy22 ×××××××× ww002 2 + y+ y11 ×××××××× ww00
1 1
++ yy00 ×××××××× ww0000 , , ………………. (11). (11)
Formula N = sum of the yp (Base)p
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 32
Assume place value and base (weight)Assume place value and base (weight)
�� p = place of the octalp = place of the octal--digit = 0, 1, digit = 0, 1, 2, 2, ……., (pmax ., (pmax –– 3), (pmax 3), (pmax –– 2) or 2) or (pmax (pmax –– 1), from right to left1), from right to left
�� pmax = maximum the number of pmax = maximum the number of places used in the representation places used in the representation andand
�� w0 = base (basic weight) = 8w0 = base (basic weight) = 8
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 33
0909dd = 11= 1188 = 00001001= 00001001bb=1 =1 ×××××××× ww00
1 1 ++ 1 1 ×××××××× ww000 0
………………………………………… (12) (12) ww0 0 = 8= 8
A Formula
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 34
1212dd = 14= 1488 = 00001100= 00001100bb= 1 = 1 ×××××××× ww00
1 1 ++ 4 4 ×××××××× ww000 0
……………………………………………… (13) (13) ww0 0 = 8= 8
A Formula
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 35
01000100dd = 144= 14488 = = 011001100010000100bb = 1 = 1 ×××××××× ww00
1 1 + 4 + 4 ×××××××× ww00
1 1 + + 4 4 ×××××××× ww0000
……………………………… (14) (14)
ww0 0 = 8= 8
A Formula
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 36
10241024dd = 2000= 200088 = = 2 2 ×××××××× ww00
3 3 + 0 + 0 ×××××××× ww002 2 ++ 0 0 ×××××××× ww00
1 1
+ + 0 0 ×××××××× ww0000
……………………………… (15) (15)
ww0 0 = 8= 8
A Formula
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 37
Outline• Hexadecimal system• 2 or 4 or 8 hex-digit representation• BCD system• 2 or 4 BCD digit representation• Octal system•• ConversionConversion
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 38
••Let decimal number be 56Let decimal number be 56ddAt 7At 7thth digit place, digit = 56/2digit place, digit = 56/27 7 = = 56/128 = 0 (remainder = 56)56/128 = 0 (remainder = 56)At 6At 6thth digit place, digit = 56/2digit place, digit = 56/26 6 = = 56/64 = 0 (remainder = 56) 56/64 = 0 (remainder = 56)
Conversion from Decimal Number to Hexadecimal
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 39
••At 5At 5thth digit place, digit = 56/2digit place, digit = 56/25 5 = = 56/32 =1 (remainder = 24) 56/32 =1 (remainder = 24) At 4At 4rthrth digit place, digit = 24/2digit place, digit = 24/24 4 = = 24/16 = 1 (remainder = 8)24/16 = 1 (remainder = 8)At 3At 3rdrd digit place, digit = 8/2digit place, digit = 8/23 3 = 8/8 = 8/8 = 1 (remainder = 0) = 1 (remainder = 0)
Conversion from Decimal Number to Hexadecimal
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 40
••At 2At 2ndnd digit place, digit = 0/2digit place, digit = 0/22 2 = 0/4 = 0/4 = 0 (remainder =0). = 0 (remainder =0). At 1At 1stst digit place, digit = 0/2digit place, digit = 0/21 1 = 0/2 = 0/2 = 0 (remainder = 0). = 0 (remainder = 0). At 0At 0thth digit place, digit = 0/2digit place, digit = 0/20 0 = 0/1 = 0/1 = 0 (remainder = 0). = 0 (remainder = 0).
Conversion from Decimal Number to Hexadecimal
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 41
••Binary number is 00111000Binary number is 00111000bb. Each . Each nibble (a set of 4 bits) can be nibble (a set of 4 bits) can be directly converted to hexdirectly converted to hex--digits as digits as follows. follows. At 1At 1st st digit place, hex digit = 0011digit place, hex digit = 0011bb= 3= 3d d = 3= 3h h At 0At 0thth digit place, hex digit = 1000digit place, hex digit = 1000bb= 8= 8d d = 8= 8hh
Ch02L2-"Digital Principles and Design", Raj Kamal, Pearson Education, 2006 42
••Therefore, HexTherefore, Hex--number = 38H. number = 38H. corresponding to decimal value 56corresponding to decimal value 56ddbinary number = 00111000binary number = 00111000bb, and , and hexadecimal number = 38H.hexadecimal number = 38H.
Binary from Hexadecimal
• A hexadecimal number has hex-digits between 0 and F and each hex-digit is four bits (1- nibble)
• A BCD number has decimal digits between 0 and 9 and each BCD digit stores as four bits (1- nibble).
• BCD numbers are used because of ease in processing by computer in their binary form
• Hexadecimal numbers are used because of ease in processing by computer in their binary form