Chapter 2
Chapter 2
and Codes
1. Introduction, decimal, binary, octal and hexadecimal number
systems.
2. Conversions between number systems.
3. Number codes: Gray, BCD and ASCII.
4. Representation of negative numbers: sign and magnitude, one’s
complement and two’s complement.
5. Arithmetic operations on binary numbers and two’s complement
numbers
OCTAL HEXADECIMAL
A way to represent binary number Commonly used simpler way to represent binary
Each digit starts from 0 to 8 (Octa.. Get it?) number
Each digit starts from 0 to 15
2732148 10 12 13 14 15 are represented with A B C D E F
𝐵𝐴𝐵𝐸1238
(STB24403 Digital Electronics)
Conversions between number systems.
Conversion To Decimal
Binary 𝟐𝟒 𝟐𝟑 𝟐𝟐 𝟐𝟏 𝟐𝟎 In decimal
11101 1 × 16 + 1 × 8 + 1 × 4 + 0 × 2 + 1 × 1
16 8 4 2 1
1 1 1 0 1
29
Octal 𝟖𝟑 𝟖𝟐 𝟖𝟏 𝟖𝟎 In decimal
7205 512 64 8 1 7 × 512 + 2 × 64 + 0 × 8 + 5 × 1
7 2 0 5 3717
001100101101011100111011
1 4 5 5 7 3 11=B
1455 73B
4 6 2 1 F=15 3 B=11
100110010001111100111011
100110010001 111100111011
BCD 0 1 1 1 0 1 0 0 1 0 0 1 0 0 1 1
𝑿𝑿𝑿𝑿𝑿𝑿𝑿𝑿𝟐
Sign indicates if the number if +ve (0) or –ve (1)
Magnitude is the value of the number in true binary
(uncomplemented)
+𝟑𝟗𝟏𝟎 = 𝟎𝟎𝟏𝟎𝟎𝟏𝟏𝟏𝟐
−𝟑𝟗𝟏𝟎 = 𝟏𝟎𝟏𝟎𝟎𝟏𝟏𝟏𝟐
(STB24403 Digital Electronics)
Representation Of Negative Numbers
1’s Complement
+ve numbers are similar to sign-magnitude
-ve numbers are the complements/inversion of the +ve
number.
𝐗𝐗𝐗𝐗𝐗𝐗𝐗𝐗 𝟐 𝟏𝟎𝟎𝟏𝟏𝟏𝟎𝟏𝟐
𝐗𝐗𝐗𝐗𝐗𝐗𝐗𝐗 𝟐 𝟎𝟏𝟏𝟎𝟎𝟎𝟏𝟎𝟐
(STB24403 Digital Electronics)
Representation Of Negative Numbers
2’s Complement
+ve numbers are similar to sign-magnitude
-ve numbers are the complements/inversion of the +ve
number and then added with 1
Most widely used signed number
Positive number 𝐗𝐗𝐗𝐗𝐗𝐗𝐗𝐗 𝟐 𝟎𝟏𝟏𝟎𝟏𝟏𝟎𝟏𝟐
-ve in 1’s compement 𝐗𝐗𝐗𝐗𝐗𝐗𝐗𝐗 𝟐 𝟏𝟎𝟎𝟏𝟎𝟎𝟏𝟎𝟐
-ve in 2’s complement 𝐗𝐗𝐗𝐗𝐗𝐗𝐗𝐗 𝟐 + 𝟏 𝟐 𝟏𝟎𝟎𝟏𝟎𝟎𝟏𝟏𝟐
(STB24403 Digital Electronics)
Representation Of Negative Numbers
Determine the decimal value of 101100002 expressed in
sign-magnitude
101100002
Sign 𝟐𝟔 𝟐𝟓 𝟐𝟒 𝟐𝟑 𝟐𝟐 𝟐𝟏 𝟐𝟎
1 0 1 1 0 0 0 0
− 25 + 24 = −48
110011112
−𝟐𝟕 𝟐𝟔 𝟐𝟓 𝟐𝟒 𝟐𝟑 𝟐𝟐 𝟐𝟏 𝟐𝟎
1 1 0 0 1 1 1 1
= −27 + 26 + 23 + 22 + 21 + 20
= −128 + 64 + 8 + 4 + 2 + 1
= −49 (−𝒗𝒆 𝒉𝒂𝒗𝒆 𝒕𝒐 𝒂𝒅𝒅 𝟏)
= −𝟒𝟗 + 𝟏
= −𝟒𝟖
*If MSB is 0, use normal way of finding decimal
= −27 + 26 + 23 + 22 + 21 + 20
= −128 + 64 + 16
= −𝟒𝟖
*If MSB is 0, use normal way of finding decimal
(STB24403 Digital Electronics)
Representation Of Negative Numbers
Total combination of n bits = 𝟐𝒏
Range of signed number of n bit = −𝟐𝒏−𝟏 to + 𝟐𝒏−𝟏 − 𝟏
* (n-1) because MSB is the sign bit
Binary subtraction
0-0 =0
01 10 1 0
1-0 =1
Borrow 1 from higher bit = value of 2
1-1 =0 - 0 1 1 0
10 - 1 =1 0 1 0 0
Hexa Substraction
01 1 1 01 01 11 11 1
+ 0 1 0 1 1 0 0 1
Left BCD Invalid because > 9
Right BCD invalid because
1 11 1 0 0 0 0 0 0 generate carry
+ 0 1 1 0 0 1 1 0 Add 6 to each invalid
0 0 0 1 0 0 1 0 0 1 1 0 Valid BCD
1 2 6