CHAPTER ONE
NUMBER SYSTEMS
AND CODES
Objectives
Binary, octal, hexadecimal and BCD number systems.
Number Conversion
2
1.1 Binary Numbers
The binary number system is used to represent the voltage levels of a
digital circuit. Only two voltage levels present in a digital circuit, logic
High (1) and logic Low (0). The high voltage is +5V and the low voltage is
+0V.
Output dalam desimal
proses dalam binari
Input dalam desimal
A calculator is an example of a digital system. Decimal numbers are
pressed on the keypad, where the input values are converted to binary for
processing, then converts the answer to a decimal value before displaying
them. Number conversion occurs extensively in a digital circuit. In this
chapter, you will learn number systems and codes used in digital circuit.
You will also learn how to perform conversion from one number system to
another.
A decimal number 8710 can be converted to a binary number by
successively dividing the number by 2 as follows:
87 ÷ 2 = 43 remainder 1 LSB (right-most bit)
43 ÷ 2 = 21 remainder 1
21 ÷ 2 = 10 remainder 1
10 ÷ 2 = 5 remainder 0
5÷2=2 remainder 1
2÷2=1 remainder 0
1 ÷ 2= 0 remainder 1 MSB (left-most bit)
Therefore 8710 = 10101112
Note that the last remainder becomes the most significant bit (MSB) and
the first remainder becomes the least significant bit (LSB).
3
A binary number 10101112 is converted to a decimal number by summing
together the weights of various positions in the binary number which
contains a 1.
MSB LSB
26 25 24 23 22 21 20 Bit Weights
1 0 1 0 1 1 1 binary number
= 26 + 24 + 22 + 21 + 20
= 64 + 16 + 4 + 2 + 1
= 8710.
1.2 Octal Number
A decimal number 26610 can be converted to an octal number by
successively dividing the number by 8 as follows:
266 ÷ 8 = 33 remainder 2 LSD (right-most digit)
33 ÷ 8 = 4 remainder 1
4÷8=0 remainder 4 MSB (left-most digit).
Therefore 26610 = 4128
To convert an octal number 4128 to a decimal number, multiply each
octal value by the weight of the digit and sum the results.
MSD LSD
82 81 80 Octal Digit Weights
4 1 2 Octal Number
= (4 x 82 ) + (1 x 81) + (2 x 80)
= 256 + 8 + 2
= 26610.
4
Each octal digit can be represented by a 3-bit binary number as shown
below:
Octal Digits 3-bit Binary number
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Conversion from octal to binary is very straightforward. Each octal digit is
replaced with a 3-bit binary number. For example, 4728 = 100 111 0102.
4 7 2 Octal number
↓ ↓ ↓
100 111 001 Binary number
A binary number is converted into an octal number by taking groups of 3
bits, starting from LSB, and replacing them with an octal digit. For
example, 110101102 = 3268.
011 010 110 Binary number
↓ ↓ ↓
3 2 6 Octal number
1.3 Hexadecimal Number
The hexadecimal number (base 16) uses the digits 0 through 9 plus the
letters A, B, C, D, E and F. The letter A stands for decimal 10, B for 11, C
for 12, D for 13, E for 14 and F for 15.
Hexadecimal Decimal Binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
A decimal number 42310 can be converted to a hex number by
successively dividing the number by 16 as follows:
423 ÷ 16 = 26 remainder 7 LSB
26 ÷ 16 = 1 remainder 10 A
1 ÷ 16 = 0 remainder 1 MSB
Therefore 42310 = 1A716
To convert the hex number 1A716 to a decimal number, multiply each hex
value by the weight of the digit and sum the results.
MSD LSD
162 161 160 Hex Digit Weights
1 A 7 Hex Number
= (1 x 162 ) + (10 x 81) + (7 x 80)
= 256 + 160 + 7
= 42310.
Conversion from hex to binary is very straightforward. Each hex digit is
replaced with a 4-bit binary number. For example, 1A716 = 1 1010
01112.
1 A 7
↓ ↓ ↓
0001 1010 0111
6
A binary number is converted into a hex number by taking groups of 4
bits, starting from LSB, and replacing them with a hex digit. For example,
For example, 101111110101102 = 2FD616.
10 1111 1101 0110
↓ ↓ ↓ ↓
2 F D 6
1.4 BCD Code
Conversions between decimal and binary can become long and
complicated for large numbers. Converting a large number such as 87410
to a binary number 11011010102 will take quite a lot of time. We call this
straight binary coding.
The Binary-Coded-Decimal (BCD) code makes conversion much easier.
Each decimal digit, 0 through 9, is represented with a 4-Bit BCD code as
shown below. The BCD code 1010, 1011, 1100, 1101, 1110 and 1111
are not used.
Decimal Digit BCD Code
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
Conversion between BCD and decimal is accomplished by replacing a 4-
bit BCD for each decimal digit. For example, 87410 = 1000 0111 0100BCD.
8 7 4 decimal number
↓ ↓ ↓
1000 0111 0100 BCD code
BCD is not another number system like binary, octal, decimal and
hexadecimal. It is in fact the decimal system with each digit encoded in its
7
binary equivalent. A BCD code is not the same as a straight binary
number. For example, the BCD code requires 12 bits, while the straight
binary number requires only 10 bits to represent 87410.
87410 = 11011010102 binary
87410 = 1000 01110100BCD BCD
A BCD code is converted into a decimal number by taking groups of 4
bits, starting from LSB, and replacing them with a BCD code. For
example, 1100101111000 BCD = 197810
1 1001 0111 1000 BCD code
↓ ↓ ↓ ↓
1 9 7 8 decimal number
8
Exercises
1. Convert decimal 23410 to
a. binary
b. BCD
b. octal
c. hexadecimal
2. Convert binary 10010111012 to
a. decimal
b. octal
c. hexadecimal
d. BCD
3. Convert hexadecimal ABF216 to
a. decimal
b. binary
c. octal
d. BCD
4. Convert BCD 10010100100110001BCD to
a. decimal
b. octal
c. hexadecimal
d. binary
5. Convert number octal 5268 to
a. decimal
b. BCD
c. hexadecimal
d. binary
6. Convert the following decimal numbers to octal and binary.
a. 87 b. 266 c. 10 d. 20
7. Convert the following decimal numbers to hexadecimal and binary.
b. 87 b. 266 c. 56 d. 20