Number System & Codes
Number System & Codes
Number System & Codes
INTRODUCTION
Digital electronics evolved from the principle that transistor circuitry could
easily be designed and fabricated to output one of the two voltage levels
based on the levels placed at its input. The two distinct levels (usually 5V
and 0V) can be represented by 1 and 0.
Numerical Representation
There are two ways of representing the numerical values of quantities:
analog and digital
1
Disadvantages of Digital techniques
There is only one major drawback with the digital techniques, that the real-
world problems are analog. Thus to take advantage of digital techniques
when handling analog quantities, the following three steps are used:-
a) Convert the real-world inputs to digital form
b) Process the digital information
c) Convert the digital outputs back to real-world analog form
As an illustration, a flow rate measurement and control system is as
shown in fig. 1.
Analog-to- Digital
Measurin
digital signal
g device
converter processing
Flow rate
(analog)
Digital-to Adjusts
Flow rate
analog flow rate
controller
converter
2
NUMBER S YST E M AND C O D E S
Number system can be defined as the representation of values using
special symbols.
There are several number systems but most commonly used ones in
digital electronics are
a) Decimal number system
b) Binary number system
c) Octal number system
d) Hexadecimal number system
This number system has a radix or base of 10 that is, it contains ten
unique symbols (or digits) use to represent numbers. These are:
0.1,2,3,4,5,6,7,8,9. Any of these may be use in each position of the
number. (Radix is defined as the number of different digits which can
occur in each position in the number system)
Also this number system is a position-value system which means that the
value of a digit depends on its position. The absolute value of each digit is
fixed but its position value (or place value or weight) is determined by its
position in the overall number. For example,
4 4 4 4
Fig 2
The weights of each position can be expressed a powers of 10. For
example, the number 3547.216 can be represented as follows:-
3 5 4 7 . 2 1 6
3
by third (12), etc. thus the numbers are 10, 11, 12, … 1 9 , 20, 21, 22, …
29, 30, 31, 32, …
It has a radix of 2 that is; it uses only two digits 0 and 1 to represent
numbers. Thus, all binary numbers consist of a string of 0s and 1s e.g.
10, 101 and 1011.To avoid confusion with decimal numbers; a subscript
of 10 is used for decimal and 2 for binary e.g.
1 0 1 0 , 1 0 1 1 10 , 5742 10 - decimal n u m b e r s a n d
1 0 2 , 1 0 1 2 , 1 1 0 0 0 0 1 2 – binary n u m b e r s
Like decimal number system, binary system is also positionally-weighted.
However, the position value of each bit corresponds to some power of 2 as
illustrated fig.4.
The position values of different bits are given by ascending powers of 2 to
the left of binary point and by descending power of 2 to the right of binary
point
1 1 0 1 . 0 1 1
4
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
13 1 1 0 1
14 1 1 1 0
15 1 1 1 1
It may be noted from the table that four bits (or digits) are needed to
count from 0 to 15 (i.e. 2 4 -1). In general with n bits, we can count up to a
number equal to 2 n - 1. Thus,
Largest decimal number = 2 n – 1
For example, if n = 5, then we can count from 0 to (25 - 1) = 31.
Exercise
What is the largest decimal value that can be represented by (a) a 8-bit
binary, (b) a 16-bit binary number?
5
Step 1 . 1 0 1
1 1
Step 4 2 8 0.625
0.1012 0.62510
Example 3 Convert the binary number 101.101 into its decimal equivalent.
1 0 1 . 1 0 1
101.1012 = 5.62610
Decimal-to-Binary Conversion
There are two methods of decimal-to-binary conversion;
(i) Sum-of-weights method and
(ii) Repeated division by-2 method
9 8 1 or 9 23 20
Placing 1s in the appropriate weight positions, 23 and 20 and 0s in the 22 and
21 positions, we can write the binary number for decimal 9 as
23 22 21 20
1 0 0 1
91 0 10012
6
Example 5 Convert each of the following decimals numbers to their binary
equivalent using sum-of-weights methods:
a) 17
b) 24
c) 61
d) 93
24 23 22 21 20
1 0 0 1
0
171 0 100012
b) Given the decimal number 24
24 16 8 2 4 2 3
Placing 1s in the appropriate weight positions, 24 and 23 and 0s in the 22 ,
21 and 20 positions, we can write the binary number for decimal 24 as
24 23 22 21 20
1 1 0 0 0
241 0 11000 2
61 32 16 8 4 1 25 2 4 23 2 2 2 0
7
25 24 23 22 21 20
1 1 1 1 0 1
611 0 1111012
93 64 16 8 4 1 2 6 2 4 2 3 2 2 2 0
26 25 24 23 22 21 20
1 0 1 1 1 0 1
1 ÷ 2 = 0 With a remainder
1 0 1010 2
10of 1
9
It has a radix of 8 i.e. it‟s composed of eight digits 0,1,2,3,4,5,6, and 7. To
count beyond 7, two digit combinations in the same way as in decimal and
binary is formed. Thus beyond 7, we count as 10, 11, 12,13,14,15, 16, 17,
20, 21 …
With n octal digits, we can count from 0 to (8n -1). For example, with 2
octal digits positions we c a n c o u n t for 0 0 8 to 7 7 8 .
The position value for each digit is given by different powers of 8 as shown
below:
.
8+4 8+3 8+2 8+1 80 8-1 8-2 8-3
Octal point
Table 2 shows the binary and octal numbers corresponding to the first ten
decimal numbers.
The procedure is the same that for binary-to-decimal except that s digit of
8 is used instead of 2.
10
2 0 6 . 1 0 4
82 81 80 8-1 8-2 8-3
2
0
1
4
3
206.104 8 2 8 6 1 8 1 8 4 8
128 6 8 512
134 17
128
10
11
Top
with a carry 2
0.3125 × 8 = 2.50 = 0.50
This is achieved by converting each octal digit into its 3-bit binary
equivalent. Table 3 shows the 3-bit binary equivalent for the octal digits
0, 1, 2 , … 7.
Octal Binary
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Thus using table 3 octal-to-binary conversion can be achieved.
1 3
001 011
138 0010112 or simply 10112
Exercise Convert the following octal numbers to their
binary equivalent
a) 321
b) 4653
c) 13274
12
Example 15 Convert 10111010 to octal equivalent
2 7 2
101110102 2728
Example 16 Convert 110101111.1001001 to octal equivalent.
.
110 101 111 100 100 100
6 5 7 4 4 4
110101111.10010012 657.4448
Step a E 5
14
Step a 0. 1 2
E x a m p l e 2 0 Co nv e rt 2 D 6 1 6 to its equivalent b i n a r y n u m b e r
15
Step a 2 D 6
Step c 001011010110
2D61 6 1011010110 2
Step a 1 0 1 1 1
Three zeros
are added to
form a four-bit
group
Step c 1 7
101112 171 6
Exercise Convert the following binary numbers to their hexadecimal
equivalents.
a) 10100110
b) 1111110000
c) 100110000010
16
However the first method is m uc h simpler and convenient. The procedure
is as follows:-
a) Write the hexadecimal number
b) Replace each hexadecimal digit by its 4-bit binary equivalent.
c) Form 3-bit combinations by starting from the right-most position.
Replace each 3-bit combination by its octal equivalent.
2 7 0 2
5C216 27028
A 7 3 B
2 4 7 1 6 6
A7.3B16 247.1668
17
Step a 3 2 1
D 1
3218 D116
ARITHMETIC OPERATIONS
Binary Addition
The following rules are
used 0 + 0 = 0
0+1=1
1+0=1
1 + 1 = 10 i.e. 0 with a
carry over of 1
Binary Subtraction
18
Example 26 Perform the following binary subtractions
a) 110.01 – 100.1
b) 11.01111 – 10.01001
Solutions
a) 1 1 1 . 0 1 b) 1 1 . 0 1 1 1 1
- 1 0 0 . 1 0 -1 0 . 0 1 0 0 1
0 1 . 0 0 1 1 0
0 1 0 . 1 1
19
E x a m p l e 2 9 Subtract 1 0 1 2 from 1 1 1 2
1 1 1
+ 0 1 0 1's complement of subtrahend 101
1 0 0 1
1 end-around carry
0 1 0
E x a m p l e 3 0 Subtract 1 1 0 1 2 from 1 0 1 0 2
1 0 1 0
+ 0 0 1 0 1's complement of subtrahend 1101
1 1 0 0
No carry
recomplementing the answerand attaching a vesign have 00112
Drop carry
1 0 1 0
+ 0 0 1 1 2's complement of subtrahend 1101
1 1 0 1
No carry
Since there is no carry, the answer must be recomplemented. First we must
subtract 1 from it to get 1100 and recomplement to get 0011. After attaching
the minus sign, the
20
final answer is - 0 0 1 1 2 .
Exercise
Perform the following binary subtraction using 2‟s complement arithmetic.
(i) 11011 – 11001
(ii) 11011.00 – 1100.00
(iii) 0.01111 – 0.01001
(iv) 111.01 – 10.111
(v) 111.01 – 110.11
(vi) 10111.1 – 10011.1
Both are simple and is done just like decimal multiplication and division.
Example 27 Perform the following binary multiplication
a) 1.01× 10.1
b) 101.01 × 11
Solutions
a) 1 . 0 1
×1 0 . 1 .
b) 1 0 1 0 1
1 0 1
× 1 1
0 0 0
1 1 1 1 0 1 0 1
1 1 . 0 0 1
1 0 1 0 1
1 1 1 1. 1 1
Example 28 Convert the following binary divisions
a) 1111001 ÷ 1001
b) 11.11 ÷ 0.101
Solutions
21
a) 1101.0111
1001 1111001
1001
1100
1001
01101
1001
10000
1001 b) 101
01110 0.101 11.110
1001 101
1010 101
1001 101
Exercise
(i) C o nver t 1 0 1 0 0 1 1 001
2 to h exa d e c i m a l
00
(ii) C o nver t 6800 10 to octal
(iii) Find decimal equivalent of binary number 0.0111
(iv) Convert the following decimal numbers to their equivalent octal
numbers
a) 4429.625
b) 791.125
c) 11.9375
CODES
Codes have been used for security reasons so that others may not be able
to read the message even if it is intercepted.
In modern digital equipments, they are used to represent and process
numerical information.
The choice of codes depends on the function it has to serve. They are
used
:-
a) to perform arithmetic operations.
b) to store and transmit information because of their high efficiency
i.e. the give more information using fewer bits.
c) to simplify and reduce the circuitry required to process information.
d) to detect and correct errors in digital circuits.
Some of these are:-
22
E ach decimal digit is represented by a group of four bits. Since the right-
to-left weighing of the 4-bit position is 8-4-2-1, it is also called an 8421
code.
The coding is as shown in the table.
Decimal BCD
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
23
BCD Addition
In this addition, three cases normally occurs
1) S u m is equal to or less than 9 and carry is 0
2) S u m is greater than 9 and carry is 0
3) S u m is less than or equal to 9 but carry is 1
7 011 1
6 0110
1101 Invalid BCD number with 0
carry 0110 We add 6 for correction
1 0011 valid BCD number with
carry 1
1 3
Hence,
710 610 1310
9 10 0 1
8 10 0 0
1 0 0 01 Sum is valid BCD number and carry 1
0001 0001 Incorrect BCD result
0000 0110 We add 6 for
correction 0001 0111 corrent
BCD result
1 7
Hence,
910 810 1710
24
Example 4: Add 5710 to 2610 in B C D
57 0111
0101 0110
26 1101 Sum is valid BCD number and carry
0 BCD
0010 valid BCD Invalid
83 0111
0111 1101 Incorrect BCD result
0000 0110 We add 6 for
correction
1000 0011 corrent BCD result
8 3
Hence,
5710 2610 8310
BCD Subtraction
This can be performed using one of the following
(i) Nine‟s complement method
(ii) Ten‟s complement method
Decimal digit 0 1 2 3 4 5 6 7 8 9
9‟s complement 9 8 7 6 5 4 3 2 1 0
25
This subtraction is similar to 1‟s complement subtraction with the steps
being ( Assu me A B C D - B B C D ) : -
1. Obtain 9‟s complement of B
2. Then, add A and 9‟s complement of B
3. If a carry is generated, then add it to the s u m to obtain the final
result.
4. If a carry is not produce then the result is negative and hence we take the
9‟s complement of the result.
7
6 9's complement of 3
1 3
1 add carry to the
sum
4 Final resuslt is
4 positive an is in the true
0100
form
+ 2 0010 9's complement of 7
0 0110
E xample 7: Perform 410 final
Since 710 carry is 0, the result is
using 9‟s complement. negative obtained by taking 9's
complement of the result
Taking the 9‟s complement of the result have:
9 1001
- 6 0110
3 0011
Hence, 410
710 310
27
The 10‟s complement of 4 is 910 410 510 1 610
Add 910 to the 10‟s complement of 410
9 10 01
6 0110
1111 invalid BCD
0110 add 01102 for correction
1 0101 discard the final carry
Therefore, 910 410 510
28
Example 13: Perform 2210 5410 using 10‟s complement method.
Solution:
The 9‟s complement of 54 is 99 54 45
The 10‟s complement of 54 is 45 1 46
Add 2210 to the 10‟s complement of 5410
22 0 010 0010
46 0110
0100 1000 since there was no final carry, then the aswer is negative
0110
valid BCD valid BCD
6 8
The 10‟s complemen t of 68 is 99 68 311 32
Therefore, 2210 5410 3210
ASSIGNMENT I
1. Convert the following numbers to Decimal, Hexadecimal and Octal form:
a) 101101.11012 [4 marks]
b) 11011011.1001012 [4 marks]
2. Convert 2AC5.D16 to decimal, octal and binary. [3 marks]
3. Using 2‟s complement perform the following: 4210 6810 . [4 marks]
4 . Solve DDCC16 BBAA16 ... 16 . [2 marks]
5 . Solve 7238 2378 ... . [2 marks]
8
29