Number System & Codes

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 29

DIGITAL E L EC T RO N I C S AND LO G I C

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

(i) Analog Representation


 It‟s a numerical representation in which a quantity is represented
by a voltage, current, or meter movement that is proportion to the
value of that quantity e.g. car speedometer, the electric iron
thermostat, audio microphone.

(ii) Digital Representation


 It‟s a representation in which a quantity is represented by the
symbols called digits e.g. digital watch. That is, digital
representation represents discrete quantities or changes in discrete
steps.

Advantages of digital techniques


Some of the reasons for shifting from analog to digital are:
a) Digital systems are easier to design – this is due the fact that circuits
which are used in digital systems are switching circuits thus easy to
design.
b) Storage of information is easy – this is accomplished by special
switching circuits that can latch onto information and hold it for a time as
long as necessary.
c) Greater accuracy and precision – these systems have a capability to
handle as many digits of precision as needed by simply adding more
switching circuits.
d) Operation can be controlled by a program – it‟s easy to design digital
systems whose operation is controlled by set of stored instruction called a
program.
e) Digital systems are less affected by noise – unwanted fluctuations (or
noise) in voltage are not as critical in digital as it is in analog systems.
This is because in digital systems, the exact value of the voltage is not
important.
f) More digital circuitry can be fabricated on IC devices

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

Fig. 1 illustrating a flow measurement and control


system

Examples of Digital Systems


Some of digital systems used in day-to-day life are:-
a) In communication systems
b) Business transactions
c) Traffic control
d) Medical treatment
e) Industrial applications
f) Digital telephones
g) Digital TV and disks
h) Digital cameras
i) Weather monitoring
j) Digital computers

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

Decimal 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

Four Four Four


Thousand Forty Hundred

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

10+3 10+2 10+1 100 10-1 10-2 10-3


Decimal point
Fig. 3 Illustrating position values as powers of 10 in a
decimal number system
 The powers are numbered to the left of the decimal point starting
with 0 and to the right of the decimal point starting with -1.
 To count beyond 9, two digit formations are used. That is, the second
digit followed by first (10), second followed by second (11), second followed

3
by third (12), etc. thus the numbers are 10, 11, 12, … 1 9 , 20, 21, 22, …
29, 30, 31, 32, …

Binary Number System

 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

2+3 2+2 21 20 2-1 2-2 2-


3 Binary point
Fig. 4 Illustrating position values as powers of 2 in a
binary number system
 To count beyond 1, the same process is used as in decimal. That is,
second followed by firs (10), second followed by second (11), second
followed by first followed by first (100), etc. Hence the numbers after 1
are 10, 11, 100, 101, 110, 111 …
 Table 1 below shows a binary count from 0 through 15 and their
decimal equivalent.

Table 1 Counting in Binary

Decimal Binary number


number
2 +3 2 +2 2 +1 20
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0

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?

Integer Binary-to-Decimal Conversion


 The following procedure is used to convert a given binary integer (whole
number) in its equivalent decimal number.
(i) Write the binary number i.e. all bits in a row
(ii)Directly under the bits, write 1, 2, 4,8,16 … starting form right to left
(iii)Cross out the decimal weight which lie under 0 bits.
(iv)Add the remaining weights to get the decimal equivalent

Example 1 Convert 11001 to its equivalent decimal number


Step 1 1 1 0 0 1
Step 2 16 8 4 2 1
Step 3 16 8 4 2 1
Step 4 16 + 8 + 1 = 25

Hence, 110012 = 2510

Fractional Binary-to-Decimal Conversion


 The procedure is the same as for binary integers except that the weights
after binary point have negative powers.

Example 2 Convert the fraction 0.101 into its decimal equivalent.

5
Step 1 . 1 0 1

Step 2 2-1 2-2 2-3

Step 3 2-1 2-2 2-3

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

4 2 1 2-1 2-2 2-3


4+1+0.5+0.125

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

(i) Sum-of-weights method for Integer Decimal-to-Binary Conversion


 It uses the binary weights. To find the binary number that is equivalent to
a given decimal number is to determine the set of binary weights whose
s u m is equal to the decimal number. For example, a list of the first eight
binary weights from right to left is: 128, 64, 32, 16, 8, 4, 2, 1.

Example 4 Convert 9 to binary equivalent

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

a) Given the decimal number 17


17  16  1  2 4  2 0
Placing 1s in the appropriate weight positions, 24 and 20 and 0s in the
23 ,
22 and 21 positions, we can write the binary number for decimal 17 as

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

c) Given the decimal number 61

61  32  16  8  4  1  25  2 4  23  2 2  2 0

Placing 1s in the appropriate weight positions, 25 , 24 , 23 , 20 and 0s in the


21 positions, we can write the binary number for decimal 61 as

7
25 24 23 22 21 20

1 1 1 1 0 1
 611 0  1111012

d) Given the decimal number 93

93  64  16  8  4  1  2 6  2 4  2 3  2 2  2 0

Placing 1s in the appropriate weight positions, 26 , 24 , 23 , 22 , 20 and 0s in


the 25 and 21 positions, we can write the binary number for decimal 93 as

26 25 24 23 22 21 20

1 0 1 1 1 0 1

(ii) Sum-of-weights method for Conversion of Fractional


Decimal-to- Binary
 In order to find a binary fractional number that is equivalent to a given
decimal fractional number, a set of binary weights whose s u m is equal
to the decimal number have to be determined. For example, the first
four fractional binary weights are: 0.5, 0.25, 0.125 and 0.0625.

Example 6 Convert the decimal fraction 0.625 to its equivalent binary.

0.625  0.5  0.125  2 1  2 3


 0.1012
Example 7 Convert the decimal fraction 0.375 by using sum-of-weights
method to its equivalent binary fraction.

0.375  0.25  0.125  2 2  2 3


 0.0112

(iii) Division-by-2 method for Integer Decimal-to-Binary


conversion
 The procedure is as follows:-
a) Begin by dividing the given decimal number by 2
b) Divide each resulting quotient by 2 until there is a 0 whole number
quotient.
8
c) The remainders generated by each division form the binary number.
These remainders are taken in the reverse order (from bottom to top).

Example 8 Convert the decimal integer 10 to its binary equivalent.

10 ÷ 2 = 5 With a remainder Top


of 0
5 ÷ 2 = 2 With a remainder of 1
2 ÷ 2 = 1 With a remainder of 0 Bottom

1 ÷ 2 = 0 With a remainder
1 0  1010 2
10of 1

Exercise: Convert each of the following decimal numbers using division-by-2


to its binary equivalent
a) 19
b) 68

(iv) Multiplication-by-2 for Fractional Decimal to Binary Conversion


 The procedure is as follows:-
a) Begin by multiplying the given decimal fraction by 2 and then
multiplying each resulting fractional part of the product by 2.
b) Repeat step a) until the fractional product is zero or until the desired
number of decimal places is reached.
c) The carried bits or carries generated by the multiplication produce the
binary number. These carries are taken in the forward direction.

Example 9 Convert the fractional decimal 0.3125 to its equivalent


binary fraction.

0.3125 × 2 = 0.625 with a carry 0 Top


0.625 × 2 = 1.25 = 0.25 with a carry 1
0.25 × 2 = 0.50 = 0.50 with a carry 0
0.50 × 2 = 1.00 = 0 with a carry 1 Bottom

Exercise Convert the decimal fractions below to their equivalent binary


fraction (up to 4 binary places) using multiplication-by-2 method.
a) 0.9028
b) 0.777
c) 0.6667

Octal Number System

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.

Table 2: Binary and Octal Numbers corresponding to the first ten


decimal numbers

Decimal Binary Octal


0 000 0
1 001 1
2 010 2
3 011 3
4 100 4
5 101 5
6 110 6
7 111 7
8 1000 10
9 1001 11
10 1010 12

NB: A subscript of 8 or the letter O is used to signify an octal


number17 8 or 17 O .
(i) Octal-to-Decimal Conversion

 The procedure is the same that for binary-to-decimal except that s digit of
8 is used instead of 2.

E x a m p l e 1 0 C o nv e r t 2 0 6 . 1 0 4 8 into its d e c i ma l equivalent n u m b e r.

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

(ii) Decimal-to-Octal Conversion

 The double-dabble method is used with 8 acting as the multiplying factor


for integers and the dividing factor for fractions.

Example 11 Convert 17510 into its octal equivalent

With a remainder of 7 Top


175 ÷ 8 = 21
With a remainder of 5
21 ÷ 8 = 2 Bottom
With a remainder of 2
2 ÷ 8 = 0
Taking the remainders in the reverse order, we get
 17510  2578

Example 12 Convert 0.1510 into its octal equivalent.

0.15 × 8 = 1.20 = 0.20 with a carry 1 Top


0.20 × 8 = 1.60 = 0.60 with a carry 1
0.60 × 8 = 0.80 with a carry 4
= 4.80
Bottom
Taking the remainders in the forward order, we get
 0.1510  0.1148

Example 13 Convert 0.312510 into its octal equivalent

11
Top
with a carry 2
0.3125 × 8 = 2.50 = 0.50

with a carry 4 Bottom


0.50 × 8 = 4.00 = 0.00
Taking the remainders in the forward order
 0.312810  0.248

(iii) Octal-to Binary Conversion

 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.

Table 3 Octal-to-binary conversion

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.

Examples 14 Convert 138 into its binary equivalent.

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

(iv) Binary-to Octal Conversion

 This is the reverse of octal-to-binary conversion.

12
Example 15 Convert 10111010 to octal equivalent

010 111 010

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

Usefulness of Octal number System

Binary numbers especially with 64 bits are used in computers to


represent some code that convey non numerical information. They might
represent:
a) Actual numerical data
b) Numbers corresponding to a location called (address) in memory
c) An instruction code
d) A code representing alphabetic and other non numerical characters
e) A group of bits representing the status of devices internal or external
to the computer
When dealing with a large quantity of binary numbers of many bits, its
convenient and more efficient to use octal numbers than binary.

Hexadecimal Number System

 It‟s primarily used as a “shorthand” way of displaying binary numbers


because it is very easy to convert between binary and hexadecimal.
 It has a radix of 16 which means it uses 16 distinct symbols to
represent
numbers. This symbols are : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
 Place value (or weights) for each digit is in ascending powers of 16 for
integers and descending powers of 16 for fractions.
 To count beyond F, a 2-digit combination is used, that is, take the
second
digit followed by the first digit, then second followed by second, then
second followed by third and so on. The first few numbers and their
equivalents are given in table 4.
13
Table 4 Hexadecimal numbers and their decimal equivalents

Hexadecima l Decima Hexadecima l Decima Hexadecima l Decima


l l l
0 0 B 11 16 22
1 1 C 12 17 23
2 2 D 13 18 24
3 3 E 14 19 25
4 4 F 15 1A 26
5 5 10 16 1B 27
6 6 11 17 1C 28
7 7 12 18 1D 29
8 8 13 19 1E 30
9 9 14 20 1F 31
A 10 15 21 20 32

(i) Hexadecimal-to Decimal Conversion


 The following is the procedure to convert a hexadecimal number to it
equivalent decimal number.
a) Write the hexadecimal number
b) Directly under the hexadecimal number, write the position weight of
each digit working from right to left
c) Multiply the decimal value of each hexadecimal digit by its position
weight and take s u m of the products.

Example 17 Convert E5 to its equivalent decimal number

Step a E 5

Step b 16+1 160

Step c (E × 16+1) + (5 × 160)


= (E × 16) + (5 × 1)
= (14 × 16) + (5 × 1)
= 224 + 5
= 229
 E516  22910

E x a m p l e 1 8 Co nv e rt 0 . 1 2 1 6 to its equivalent d e c i ma l fraction.

14
Step a 0. 1 2

Step b 16-1 16-2

Step c (1 × 16-1) + (2 × 16-2)


= 0.0625 +0.0078
= 0.0703
 0.121 6  0.07031 0

(ii)Decimal-to –Hexadecimal Conversion


The procedure is as follows;-
a) Begin by dividing the given decimal number by 16
b) Divide each resulting quotient by 16 until there is a zero whole
number quotient
c) The remainders generated by each division form the hexadecimal
number

Example 19 Convert 650 to its equivalent hexadecimal number

650 ÷ 16 = 40.625 = 40 with a remainder 0.625 0.625 × 16 = Top


10 (=A)

40 ÷ 16 = 2.5 = 2 with a remainder 0.5 0.5 × 16 = 8


Bottom
2 ÷ 16 = 0.125 = 0 with a remainder 0.125 0.125 × 16 = 2
 65010  28A16
Exercise Convert the following decimal numbers to their hexadecimal
equivalents:-
a) 2890
b) 4019.345

(iii) Hexadecimal-to-Binary Conversion


a) The procedure is as follows:-
b) Write the hexadecimal number
c) Write the 4-bit binary equivalent for each hexadecimal digit as shown in
table 5
d) Check if there are any zeros on the left most position of the binary
number obtained. Drop off the zeros and write the answer as a binary
number

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 b 0010 1101 0110

Step c 001011010110
 2D61 6  1011010110 2

(iv) Binary-to-Hexadecimal Conversion


The procedure is as follows:-
a) Write the binary number
b) Starting from the right most position, group the binary number into
groups of four-bits. If necessary, add zeros at the left-most position.
c) Convert each 4-bit binary to its equivalent hexadecimal digit

Example 21 Convert 10111 to its equivalent hexadecimal.

Step a 1 0 1 1 1

Step b 0001 0111

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

(v) Hexadecimal-to-Octal Conversion


There are two methods to accomplish this.
1. Convert the given hexadecimal number to binary equivalent and then
from binary to octal
2. Convert the given hexadecimal number to its decimal equivalent and
then from decimal to octal.

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.

Example 22 Convert 5 C 2 to its octal equivalent.


Step a 5 C 2

Step b 0101 1100 0010

Step c 010 111 000 010

2 7 0 2
 5C216  27028

E x a m p l e 2 3 Co nv e rt A 7 . 3 B 1 6 into its octal e qu i v a l e n t .

A 7 3 B

1010 0111 00111011


010100111 001 110 110

2 4 7 1 6 6
 A7.3B16  247.1668

(vi) Octal-to-hexadecimal conversion


It‟s similar to the hexadecimal-to-octal except only in group of the digits.

Example 24 Convert 3218 to its hexadecimal equivalent.

17
Step a 3 2 1

Step b 011 010 001

Step c 0 1101 0001

D 1
 3218  D116

Excise: Convert the following numbers to hexadecimal


a) 6 4 7 5 8
b) 6 4 5 . 6 7 8
c) 8 7 6 . 4 5 8

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

Example 25 Perform the


following binary additions
a) 100101 + 100101
b) 1011.01 + 1001.11
0 0 1 0+ 11011.011 1 0 1 1 .
c) 1100.011 0 1 1 1 0 0 . 0 1
Solutions 1
+1 0 0 1 0 1 +1 0 0 1 . 1 1 +1 0 1 1 . 0 1 1
1 0 0 1 01 0 1 0 1 0 1 . 1 0 1 0 1 1 1 . 1 1 0

Binary Subtraction

The following rules are


used 0 - 0 = 0
1-0=1
1-1=1
10 - 1 = 1

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

Complement of a binary number


Its possible to use the circuits designed for binary addition to perform the
binary subtraction if the problem of subtraction is change to that of addition.
This can be achieved using complements of binary numbers.
There are two binary complements: 1‟s complement and 2‟s complements

1’s complement representation


1‟s complement of a binary number is obtained by changing each „0‟ to „1‟
and each „1‟ to „0‟. For example 1‟s complement of 010111 is 101000 and 1‟s
complement of 1001.1110 is 0110.0001.

2’s complement representation


The 2‟s complement of a binary number is obtained by adding 1 to its 1‟s
complement i.e.
2‟s complement = 1‟s complement + 1
It also called true c o m p l e m e n t . For e x a m p l e , th e 2‟s co mp l emen t of 1 0 1 1 2 is
obtained as

1's complement of 1011 is 0100

2's complement of 1011 is 0100


+1
0101
 2's complement of 10112 is 01012

1’s complement subtraction


The rules are
(i) Compute the 1‟s complement of the subtrahend
(ii) Add this complement to the minuend
(iii) Perform the end –round carry of the last 1 or 0
(iv) If there is no end-around carry (i.e. 0 carry), then the answer
must recomplemented and a a negative sign attached to it.
(v) If the end-around carry is 1, no recomplementing is necessary.

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

2’s complement subtraction


The procedure is:-
(i) Find the 2‟s complement of the subtrahend
(ii) Add this complement to the minuend
(iii) Drop the final carry
(iv) If the carry is 1, the answer is positive and needs no recomplementing
(v) If the is no carry, recomplement the answer and attach minus sign.

E x a m p l e 3 1 U s e 2 ’ s complement to subtract 1 0 1 0 2 from 1 1 0 1 2


1 1 0 1
+ 0 1 1 0 2's complement of subtrahend 1010
1
1 0 0 1

Drop carry

E x a m p l e 3 2 U s e 2 ’ s complement to subtract 1 1 0 1 2 from 1 0 1 0 2

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

Binary Multiplication and Division

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:-

1) Binary Coded Decimal (BCD) Code

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

 Thus, 1010 is represented by 0001 0000 in B C D while 1710 is represented by


0001 0111 in B C D .

Note that with four-bits, sixteen numbers 24  can be represented
although in the B C D code only ten of these are used. Thus, the following
six combinations are invalid: 1010, 1011, 1100, 1101, 1110 and 1111.

Example 1: Write the decimal number 369 in B C D .


Solution: 36910  001101101001BCD
Example 2: Typically digital thermometers use B C D to drive their digital
displays. How many B C D bits are required to drive a 3-digit thermometer
display? What 12 bits are sent to display for a temperature of 157
degrees.
Solution:
There are 12 B C D bits required to drive a 3-digit thermometer display
because each B C D digit is represented by a group of four bits.
15710  000101010111BCD
Example 3: Find the equivalent decimal value for the B C D code
nu\][Pmber 0001010001110101
Solution:
0001010001110101BCD  147510

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

4) Su m is equal to or less than 9 and carry is 0

Example 1: Add 210 to 610 in B C D


20010
6  0 11 0
1000

2) Su m is greater than 9 and carry is 0

Example 2: Add 710 to 610 in B C D

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

3) Su m is less than or equal to 9 but carry is 1

Example 3: Add 910 to 810 in B C D

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

E x ample 5: Add 8310 to 3410 in B C D


83  10 0 0 0011
34  0011 0100
117 1011 011
1 BCD
Invalid BCD valid
 
1011 0111  Incorrect BCD result
0110 0000  We add 6 for
correction
 0001
0001  0111   corrent BCD result
1 1 7
Hence,
8310  3410  11710

BCD Subtraction
This can be performed using one of the following
(i) Nine‟s complement method
(ii) Ten‟s complement method

(i) BCD subtraction using Nine’s complements


The 9‟s complement of a B C D number is obtained by subtracting it from 9.
9‟s complements of various numbers are given in the table below.

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.

Example 6: Subtract 310 from 710 in B C D

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

Example 8: Perform 8310  2110 using 9‟s complement

The 9‟s complement of the 2110 is


99
 21
7
8

9'
s
co
m
pl 26
e
m
en
83  10 0 0 0011
78  0111 1000
161 1111 1011
Invalid BCD Invalid BCD
 
1111 1011  Incorrect BCD
result 0110 0110  We add 6 for
correction
1 0110 0001  corrent
BCD result
1  the end around carry
is add to get the final result
0110 0010
 
6 2
Hence, 8310  2110  6210

Example 9: Perform 5210  8910 using 9‟s


complement The 9‟s complement of the 8910 is
99
 89
10
 52  0010
0101
9's 0000
co10 0001 0010  Final carry is 0, so the sum is
m62 0110 negative
The 9‟s
pl complement of 62 is 37. Hence,
5210 e 8910  3710
m
en
(ii) BCD
t subtraction using Ten’s complements
The 10‟s
of complement is obtained by adding 1 to 9‟s complement. The 10‟s
89
complement is used to perform B C D subtraction as under:-
1. Obtain the 10‟s complement of the subtrahend
Add
2. Then, add the minuend to the 10‟s complement of the subtrahend
3. to
5210Discard the carry. If the carry is 1, then the answer is positive and in true
10 i.e.
form.
4. If a carry is not produced, then the answer is negative obtained by taking
the 10‟s complement of the answer.

E xample 10: Perform 910  410 using 10‟s complement.


Solution:
The 9‟s complement of 4 is 910  410  510

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

E xample 11: Perform 310  810 using 10‟s complement.


Solution:
The 9‟s complement of 8 is 910  810  110
The 10‟s complement of 8 is 910  810  110 1  210
Add 310 to the 10‟s complement of 810
3  0 011
2  0010
0101
since there is no carry, then
the answer should be negative
5

The n , the 10‟s complement of 510 is 9


 5  4 1  5 . Hence,
310  810  510

Example 12: Perform 5410  2210 using


10‟s complement method.
54  0101 0100
Solution:
The 9‟s78complement
 0111 1000 of 22 is 99  22 
77 161 1100 1100
Invalid BCD Invalid BCD
The 10‟s complement of 22 is 77 1 
78  
1100 1100  Incorrect BCD result
Add 5410 to the0110 10‟s complement of 6 for correction
0110  We add
2210 1 0011 0010  the end around carry is add to get the final result
 
3 2
Therefore, 5410  2210  3210

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  311  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

6. Determine the value of base x, if


a) 193x  6238 [2 marks]
b) 225x  3418 [2 marks]
7. Perform the following in B C D using 10‟s complement method.
a) 3610  2310 [3 marks]
b) 23310  64310 [4 marks]

29

You might also like