0% found this document useful (0 votes)
4 views25 pages

DigitalLogic Chapter 2

The document discusses number system conversions, detailing methods for converting between decimal, binary, octal, and hexadecimal systems, including both integer and fractional parts. It also covers the concept of complements used in digital computers for subtraction and logical operations, explaining radix and diminished radix complements for various bases. Examples are provided for each type of conversion and complement calculation.

Uploaded by

pokharelbhupen77
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views25 pages

DigitalLogic Chapter 2

The document discusses number system conversions, detailing methods for converting between decimal, binary, octal, and hexadecimal systems, including both integer and fractional parts. It also covers the concept of complements used in digital computers for subtraction and logical operations, explaining radix and diminished radix complements for various bases. Examples are provided for each type of conversion and complement calculation.

Uploaded by

pokharelbhupen77
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Number System and Codes Unit 2

1 Number System Conversion


It is often required to convert a number in a particular number system to any other number system,
e.g., it may be required to convert a decimal number to binary or octal, or hexadecimal. The reverse
is also true, i.e., a binary number may be converted into a decimal, and so on. The methods of
interconversions are now discussed.
1.1 Decimal-to-binary Conversion
To convert a number in decimal to a number in binary we have to divide the decimal number by 2
repeatedly until the quotient of zero is obtained.
Example Convert 2610 into a binary number.
Division Quotient Generated remainder
26 13 0
2
13 6 1
2
6 3 0
2
3 1 1
2
1 0 1
2
Hence the converted binary number is 110102.
1.2 Decimal-to-octal Conversion
To convert a number in decimal to a number in octal we have to divide the decimal number by 8
repeatedly until the quotient of zero is obtained.
Example Convert 42610 into an octal number
Solution
Division Quotient Generated remainder
426 53 2
8
53 6 5
8
6 0 6
8

Hence the converted octal number is 6528.

1
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
1.3 Decimal-to-hexadecimal Conversion
The same steps are repeated to convert a number in decimal to a number in hexadecimal.
Only here we have to divide the decimal number by 16 repeatedly, until the quotient of
zero is obtained.
Example 1.3. Convert 34810 into a hexadecimal number.
Solution
Division Quotient Generated remainder
348 21 12
16
21 1 5
16
1 0 1
16
Hence the converted hexadecimal number is 15C16.
1.4 Binary-to-decimal Conversion
To convert binary, octal, or hexadecimal numbers to decimal numbers we have to keep in mind
that each number systems is a positional number system and has a positional weight.
Example Convert 101102 into a decimal number.
Solution

The binary number given 1 0 1 1 0


Positional weights 43210
The positional weights for each of the digits are written in italics below each digit.

Hence the decimal equivalent number is given as:


4 3 2 1 0
1× 2 + 0 × 2 + 1× 2 + 1× 2 + 0 × 2
= 16 + 0 + 4 + 2 + 0
= 2210.

Hence, we find that here, for the sake of conversion, we have to multiply each bit with
its positional weights depending on the base of the number system.
1.5 Octal-to-decimal Conversion
Example Convert 34628 into a decimal number.
Solution
The octal number given is 3 4 6 2
Positional weights 3210
The positional weights for each of the digits are written in italics below each digit.

2
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Hence the decimal equivalent number is given as:
3 × 83 + 4 × 82 + 6 × 81 + 2 × 80
= 1536 + 256 + 48 + 2
= 184210

1.6 Hexadecimal-to-decimal Conversion


Example Convert 42AD16 into a decimal number.
Solution
The hexadecimal number given is 4 2AD
Positional weights 321 0

The positional weights for each of the digits are written in italics below each digit.
Hence the decimal equivalent number is given as:
4 × 163 + 2 × 162 + 10 × 161 + 13 × 160
= 16384 + 512 + 160 + 13
= 1706910.
2 Fractional Conversion
If the number contains the fractional part we have to deal in a different way when
converting the number from a different number system (i.e., binary, octal, or
hexadecimal) to a decimal number system or vice versa.

Example Convert 1010.0112 into a decimal number.


Solution
The binary number given is 1 0 1 0. 0 1 1
Positional weights 3 2 1 0 -1-2-3
The positional weights for each of the digits are written in italics below each digit. Hence
the decimal equivalent number is given as:

1 × 23 + 0 × 22 + 1 × 21 + 0 × 20 + 0 × 2–1 + 1 × 2–2 + 1 × 2–3


= 8 + 0 + 2 + 0 + 0 + 0.25 + 0.125
= 10.37510.

Example Convert 362.358 into a decimal number.


Solution
The oc t a l number gi ven is 3 6 2. 3 5
Positional weights 2 1 0 -1-2

The positional weights for each of the digits are written in italics below each digit.
Hence the decimal equivalent number is given as:
3 × 82 + 6 × 81 + 2 × 80 + 3 × 8–1 + 5 × 8–2

3
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
= 192 + 48 + 2 + 0.375 + 0.078125
= 242.45312510.

Example Convert 42A.1216 into a decimal number.


Solution
The hexadecimal number given is 4 2 A. 1 2
Positional weights 2 1 0 -1-2

The positional weights for each of the digits are written in italics below each digit.
Hence the decimal equivalent number is given as:
2 1 0 –1 –2
4 × 16 + 2 × 16 + 10 × 16 + 1 × 16 + 1 × 16
= 1024 + 32 + 10 + 0.0625 + 0.00390625
= 1066.0664062510.

Example Convert 25.62510 into a binary number.


Solution
Division Quotient Generated remainder
25 12 1
2
12 6 0
2
6 3 0
2
3 1 1
2
1 0 1
2
Therefore, (25)10 = (11001)2
Now, for the fractional part
0.625 0.250 0. 500
×2 ×2 ×2
1.250 0.500 1.000

1 0 1
i.e., (0.625)10 = (0.101)2

Therefore, (25.625)10 = (11001.101)2

Example Convert 34.52510 into an octal number.

4
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Solution
Division Quotient Generated remainder
34 4 2
8
4 0 4
8
Therefore, (34)10 = (42)8

Fractional Part
0.525 0.200 0. 600
×8 ×8 ×8
4.200 1.600 1.200

4 1 1

i.e., (0.525)10 = (0.411)8

Therefore, (34.525)10 = (42.411)8

Example Convert 92.8510 into a hexadecimal number.


Solution
Division Quotient Generated remainder
92 5 12
16
5 0 5
16

Therefore, (92)10=(5C)16

Fractional Part
0. 85 0.60
×16 ×16
13.60 9.60

13 9
i.e., (0.85)10 = (0.D9)16

5
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Therefore, (92.85)10 = (5C.D9)16

2.1 Conversion from a Binary to Octal Number and Vice Versa


We know that the maximum digit in an octal number system is 7, which can be
represented as 1112 in a binary system. Hence, starting from the LSB, we group three
digits at a time and replace them with the decimal equivalent of those groups and
we get the final octal number.
Example Convert 1011010102 into an equivalent octal number.
Solution
The binary number given is 101101010
Starting with LSB and grouping 3 bits 101 101 010
Octal equivalent 5 5 2
Hence the octal equivalent number is (552)8.

Example Convert 10111102 into an equivalent octal number.


Solution
The binary number given is 1 011 110
Starting with LSB and grouping 3 bits 001 011 1 1 0
Octal equivalent 1 3 6
Hence the octal equivalent number is (136)8

Since at the time of grouping the three digits in t h e above example starting from the
LSB, we find that the third group cannot be completed, since only one 1 is left out in
the third group, so we complete the group by adding two 0s in the MSB side. This is
called the left padding of the number with 0.

Now if the number has a fractional part then there will be two different classes of
groups—one for the integer part starting from the left of the decimal point and
proceeding toward the left and the second one starting from the right of the decimal
point and proceeding toward the right. If for the second class, and 1 is left out, we
complete the group by adding two 0s on the right side. This is called right-padding.

Example C o n v e r t 1101.01112 into an equivalent octal number.


Solution
The binary number given is 1101.0111
Grouping 3 bits 001 101. 011 100
Octal equivalent: 1 5 3 4
Hence the octal number is (15.34)8

Example Convert (247)8 into an equivalent hexadecimal number.

6
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Solution
Given octal number is 2 4 7
Binary equivalent is 010 100 111
= 010100111
Forming groups of 4 bits from the LSB 1010 0111
Hexadecimal equivalent A 7

Hence the hexadecimal equivalent of (247)8 is (A7)16

Example Convert (36.532)8 into an equivalent hexadecimal number.


Solution
Given octal number is 3 6 5 3 2
The binary equivalent i s 011 110 101 011 010
=011110.101011010
Forming groups of 4 bits 0001 1110 . 1010 1101
Hexadecimal equivalent 1 E . A D
Hence the hexadecimal equivalent of (36.532)8 is ([Link]) 16.

3 Complements
Complements are used in digital computers for simplifying the subtraction operation
and for logical manipulations. There are two types of complements for each number
system of base - r:
1. The radix complements or r’s complement
2. The diminished radix complements or (r-1)’s complement
When we deal with a binary system the value of r is 2 and hence the complements
are 2’s and 1’s complements. Similarly, for a decimal system, the value of r is 10 and
we get 10’s and 9’s complements. With the same logic if the number system is octal
we get 8’s and 7’s complement, while it is 16’s and 15’s complements for t h e
hexadecimal system.
3.1 The r’s Complement or Radix Complement
If a positive number N is given in base r with an integer part of n digits, the r’s complement of N
is given as:
𝑟 − 𝑁 𝑓𝑜𝑟 𝑁 ≠ 0
r's complement =
0 𝑓𝑜𝑟 𝑁 = 0

Example find 10’s complement of 5252010


Here, base of digit (r) = 10

7
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Integer part of digits (n) = total number of positive digits = 5
Given number (N) = 52520

Therefore, 10’s complement = 𝑟 − 𝑁 = 10 − 52520 = 1000000 − 52520 = 47480


Example Find 10’s complement of 0.324510
0
Since the number of digits in the integer part of the number is n = 0, we have 10 = 1.

0
The 10’s complement of (0.3245)10 is 10 – 0.3245 = 0.6755.
Similarly, for 23.324
2
The 10’s complement of (23.324)10 is 10 – 23.324 = 76.676.

If we consider a binary system then r = 2


5
The 2’s complement of (10110)2 is (2 )10–(10110)2 = (100000 – 10110)2 = 01010.
Here, r = 2, n = 5, and N = 10110 in binary
0
The 2’s complement of (0.1011)2 is (2 )10–(0.1011)2 = (1 – 0.1011)2 = 0.0101.
Now if we consider an octal system, then r = 8.
4
The 8’s complement of (2450)8 is (8 )10 – (2450)8
= (409610 – 24508)
= (409610 – 132010)
= 277610
= 53308

If we consider a hexadecimal system, then r = 16.


4
The 16’s complement of (4A30)16 is (16 )10 – (4A30)16
= (6553610 – 4A3016)

= (6553610 – 1899210)

= 4654410

= B5D0 16

3.2 The (r–1)’s Complement or diminished radix complements


If a positive number N is given in base r with an integer part of n digits and a fraction
part of m digits, then the (r-1)’s complement of N is given as
𝑟 − 𝑟 − 𝑁 𝑓𝑜𝑟 𝑁 ≠ 0
(𝑟 − 1)′𝑠 =
0 𝑓𝑜𝑟 𝑁 =0
The following examples will clarify the definition.
Example Find 9’s complement of (23450)10

8
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Here, r = 10, n = 5, m = 0 (no fractional part) and N= (23450)10
The 9’s complement is given by 𝑟 − 𝑟 −𝑁
Therefore, (23450)10 is 10 – 10 – 23450 = 76549.
5 0

Example Find 9’s complement of (0.3245)10


Here, r = 10, n = 0(number of integer part), m = 4 (number of fractional part) and N=
(0.3245)10
The 9’s complement is given by 𝑟 − 𝑟 −𝑁
Therefore, (0.3245)10 is 10 – 10 – 0.3245 = 0.6754.
0 -4

Example Find 9’s complement of (23.324)10


Here, r = 10, n = 2(number of integer part), m = 3 (number of fractional part) and N=
(23.324)10
The 9’s complement is given by 𝑟 − 𝑟 −𝑁
Therefore, (23.324)10 is 10 – 10 – 23.324= 76.675
2 -3

Example Find 1’s complement of (10110)2


Now if we consider a binary system, then r = 2, i.e., (r – 1) = 1.
Here, r = 2, n = 5(number of integer part), m = 0 (number of fractional part) and N=
(10110)2
The 1’s complement is given by 𝑟 − 𝑟 −𝑁
Therefore, (10110)2 is (2 – 2 )10– (10110)2 = (32-1)10-(10110)2 =11111 – 10110 = 01001
5 -0

Example Find 1’s complement of (0.0110)2


Here, r = 2, n = 0(number of integer part), m = 4 (number of fractional part) and N=
(0.1011)2
The 1’s complement is given by 𝑟 − 𝑟 −𝑁
Therefore, (0.0110)2 is (2 – 2 )10– (0.1011)2 = (1-0.0625)10-(0.1011)2 =0.9375 – (0.0110)2
0 -4

= 0.1111-0.0110= 0.1001
Note
➢ The 10’s complement of a decimal number can be formed by leaving all least significant
zeros unchanged, subtracting the first zero least significant digit from 10, and then
subtracting all other higher significant digits from 9.
➢ 2’s complement can be formed by leaving all least significant zeros and the first non-zero
digit unchanged, and then replacing 1’s by 0’s and 0’s by 1’s in all other higher significant
digits.
➢ 9’s complement of a decimal number is formed simply by subtracting every digit from 9
➢ 1’s complement of a binary number is formed simply by changing 1’s to 0’s and 0’s to 1’s.

9
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
➢ r's complement can be obtained from the (r-1)’s complement after the addition of r-m to the
least significant digit.

4 Binary Subtraction
Binary subtraction is also carried out in a similar method to decimal subtraction. Binary
subtraction between two numbers can be performed in three ways.
1. the direct method,
2. the r’s complement method, and
3. the (r – 1)’s complement method.
4.1 Direct Method
In this method, we borrow a 1 from a higher significant position when the minuend digit
is smaller than the corresponding subtrahend digit.
Example Using the direct method to perform the subtraction 1001 – 1000.
Solution
1 0 0 1
(–) 1 0 0 0
0 0 0 1

4.2 Subtraction with r’s Complements


When subtraction is implemented in a digital system, complement methods is found to be more
efficient as it uses only complement hardware and adder unit.
The subtraction of two positive numbers (M — N), both of base r, may be done as follows:
1. Add the minuend M to the r’s complement of the subtrahend N.
2. Inspect the result obtained in step 1 for an end carry:
a. If an end carry occurs, discard it.
b. If an end carry does not occur, take the r’s complement of the number obtained in step
1 and place a negative sign in front.
Example Using 10’s complement, subtract 72532 – 3250.
Solution
Here, M = 72532, N= 3250

Now, r’s complement of N = 𝑟 − 𝑁 𝑓𝑜𝑟 𝑁 ≠ 0


= 105-03250 = 96750
Now, M + N (r’s component) = 72530 + 96750

10
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
= 169282
Here, 1 is end carry value so it is discarded. Then the required answer = 69282

Example Using 10’s complement subtracts 3250-72532


Here, M = 3250, N= 72532

Now, r’s complement of N = 𝑟 − 𝑁 𝑓𝑜𝑟 𝑁 ≠ 0


= 105-72532 = 27468
Now, M + N(r’s component) = 03250 + 27468
= 30718
Here, no end carry present so take r’s complement i.e. r’s complement of M + N(r’s component)
is 105-30718 = 69282
Thus, the required solution is = -69282

Example using 2’s complement performs 1010100-1000100


Here, M= 1010100, and N= 1000100
Now, r’s complement of N, = (27)10 - (1000100)2 = (10000000)2 - (1000100)2 = 1111002
Now, M+Nr’s = 1010100 + 111100 = 10010000
Here, 1 is end carry so it is discarded. Then required answer is 100002

Example using 2’s complement performs 1000100 - 1010100


Here, M= 1000100, and N= 1010100
Now, r’s complement of N, = (27)10-(1010100)2 = (10000000)2-(1010100)2 = 1011002
Now, M+Nr’s = 1000100 + 101100 = 11100002
Here, no end carry present so takes r’s complement of M+Nr’s = (27)10 - 11100002
= (10000)2
Therefore, required solution is (-10000)2
Subtraction Using (r-1)’s Complement

11
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
The subtraction of two positive numbers M-N, both of base r may be done as follows.
1. Add the minuend M to (r-1)’s complement of N
2. Inspect the result obtained in step 1
a. If an end carry occurs, add 1 to the least significant digit (end – around carry). The
result is answer
b. If an end carry doesn’t occurs, take (r-1)’s complement of number obtained in step
1 and placed negative (-ve) sign.
Subtract using (r-1)’s complement
Example using (r-1)’s complement performs 72532-3250
Here, M = 72532, N= 3250

Now, (r-1)’s complement of N = 𝑟 − 𝑟 − 𝑁 𝑓𝑜𝑟 𝑁 ≠ 0


105-100-03250 = 96749
Now, M + N (r-1’s complement) = 72532 + 96749
= 169281
Here, end carry is present so, required answer is 169281 + 1= 69282

Example using (r-1)’s complement performs 1010100-1000100


Here, M= 1010100, and N= 1000100
Now, (r-1)’s complement of N = (27- 20)10 - (1000100)2
= (1111111)2 - (1000100)2
= 01110112
Now, M+N(r-1)’s = 1010100 + 0111011 = 100011112
Here, end carry is present so, the required answer is 0001111 + 1 = 10000 2

Example using (r-1)’s complement performs 1000100-1010100


Here, M= 1000100, and N= 1010100
Now, (r-1)’s complement of N = (27- 20)10 - (1010100)2
= (1111111)2 - (1000100)2
= 01010112

12
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Now, M+N(r-1)’s = 1000100 + 0101011 = 11011112
Here, no end carry is present so, (r-1)’s complement of M+N(r-1)’s is
(27- 20)10 – (1101111)2 = (1111111)2-(1101111)2
= (10000)2
Therefore, the required solution is (-10000)2

5 Binary Coding System


Computers and other digital circuits process data in binary format. Various binary codes
are used to represent data which may be numeric, alphabetic or special characters.
Electronic digital systems use signals that have two distinct values and circuit elements that have
two stable states. Binary code is the code used in digital computers based on a binary number
system in which there are only two possible states ‘0’ and ‘1’ usually called ‘OFF’ and ‘ON’. It is
possible to arrange ‘n’ bits to 2n possible states.
Binary codes are of two types
➢ Weighted Binary codes
➢ Non-weighted codes
5.1 Weighted Binary Codes
If each position of a number represents a specific weight then the coding scheme is called
weighted binary code. In such coding, the bits are multiplied by their corresponding individual
weight, and then the sum of these weighted bits gives the equivalent decimal digit.

Binary Coded Decimal (BCD) Code or 8421 Code


Binary codes for decimal digits require a minimum of 4 bits. Numerous different codes can be
obtained by arranging 4 or more bits in 10(ten) distinct possible combinations. BCD is the straight
assignment of binary equivalent.

The code is also known as 8-4-2-1 code. This is because 8, 4, 2, and 1 are the weights of the four
bits of the BCD code. The weight of the LSB is 20 or 1, that of the next higher order bit is 21 or 2,
that of the next higher order bit is 22 or 4, and that of the MSB is 23 or 8. Since four binary bits are
used the maximum decimal equivalent that may be coded is 15 10 (i.e., 11112). But the maximum
decimal digit available is 910. Hence the binary codes 1010, 1011, 1100, 1101, 1110, 1111,
representing 10, 11, 12, 13, 14, and 15 in decimal are never being used in BCD code. So these six
codes are called forbidden codes and the group of these codes is called the forbidden group in BCD
code.

13
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Example Give the BCD equivalent for the decimal number 589.

Solution
The decimal number is 589
BCD code is 0101 1000 1001
Hence, (589)10 = (010110001001)BCD

Example Give the BCD equivalent for the decimal number 69.27.
Solution.
The decimal number 69.27
BCD code is 0110 1001 . 0010 0111

Hence, (69.27)10 = (01101001.00100111)BCD

84-2-1 Code
It is also possible to assign negative weights to decimal codes, as shown by the 84-
2-1 code. In this case, the bit combination 0101 is interpreted as the decimal digit 3, as
obtained from 0 × 8 + 1 × 4 + 0 × (–2) + 1 × (–1) = 3. This is a self-complementary
code, that is, the 9’s complement of the decimal number is obtained just by changing
the 1s to 0s and 0s to 1s, or in effect by getting the 1’s complement of the
corresponding number. For example, if we change the 1s to 0s and 0s to 1s in the previous
example we have 1010, which is interpreted as decimal 6, as obtained from 1 × 8 + 0
× 4 + 1 × (–2) + 0 × (–1) = 6. And 6 is the 9’s complement of 3. This property is
useful when arithmetic operations are done internally with decimal numbers (in a binary
code) and subtraction is calculated by means of 9’s complement.
2421 Code
Another weighted code is 2421 code. The weights assigned to the four digits are 2, 4,
2, and 1. The 2421 code is the same as that in BCD from 0 to 4; however, it varies
from 5 to 9. For example, in this case the bit combination 0100 represents decimal 4;
whereas the bit combination 1101 is interpreted as the decimal 7, as obtained from 2
× 1 + 1 × 4 + 0 × 2 + 1 × 1 = 7. This is also a self-complementary code, that is, the
9’s complement of the decimal number is obtained by changing the 1s to 0s and 0s to 1s.
5.2 Non-weighted Codes
These codes are not positionally weighted. It basically means that each position
of the binary number is not assigned a fixed value. Excess-3 codes and Gray codes
are such non-weighted codes.

14
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Excess-3 Code
A decimal code that has been used in some old computers is Excess-3 code. This is a non-
weighted code. This code assignment is obtained from the corresponding value of 4-bit
binary code after adding 3 to the given decimal digit. Here the maximum value may
be 11002. Since the maximum decimal digit is 9 we have to add 3 to 9 and then get the
BCD equivalent. Like 84-2-1 and 2421 codes Excess-3 is also a self-complementary code,
that is, the 9’s complement of the decimal number is obtained by changing the 1s to 0s
and 0s to 1s. This self-complementary property of the code helps considerably in
performing subtraction operation in digital systems.

Example Convert (367)10 into its Excess-3 code.


Solution
The decimal number is 3 6 7
Add 3 to each bit +3 +3 +3
Sum 6 9 10

Converting the above sum into 4-bit binary equivalent, we have a 4-bit binary
equivalent of 0110 1001 1010
Hence, the Excess-3 code for (367)10 = 0110 1001 1010

Example Convert (58.43)10 into its Excess-3 code.


Solution

The decimal number is 5 8 4 3


Add 3 to each bit +3 +3 +3 +3
Sum 8 11 7 6

Converting the above sum into 4-bit binary equivalent, we have a 4-bit binary
equivalent of 1000 1011 0111 0110
Hence, the Excess-3 code for (367)10 = 10001011.01110110
Table 1 Binary Code for Decimal Numbers

Decimal (BCD)
digit 8421 84-2-1 2421 Excess-3
0 0000 0000 0000 0011

15
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
1 0001 0111 0001 0100
2 0010 0110 0010 0101
3 0011 0101 0011 0110
4 0100 0100 0100 0111
5 0101 1011 1011 1000
6 0110 1010 1100 1001
7 0111 1001 1101 1010
8 1000 1000 1110 1011
9 1001 1111 1111 1100

Gray Code (The Reflected Code)


The gray code belongs to a class of codes called minimum change codes, in which only one bit in
the code changes when moving from one code to the next. The Gray code is a non-weighted code,
as the position of bit does not contain any weight. The gray code is a reflective digital code which
has the special property that any two subsequent numbers codes differ by only one bit. This is also
called a unit- distance code. In digital Gray code has got a special place.
To obtain a different reflected code, one can start with any bit combination and proceed to
obtain the next bit combination by changing only one bit from 0 to 1 or 1 to 0 in any desired
random fashion, as long as two numbers do not have identical code assignments. The Gray
code is not a weighted code.
Table 2 Reflected Code

Reflected Code Decimal


Equivalent
m4 0000 0
m3 0001 1
0011 2
m2 0010 3
0110 4
0111 5
0101 6
m1 0100 7
1100 8
1101 9
1111 10
m5 1110 11
1010 12
m6 1011 13
m7 1001 14
1000 15

16
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Conversion of a Binary Number into Gray Code
Any binary number can be converted into equivalent Gray code by the following
steps:
➢ The MSB of the Gray code is the same as the MSB of the binary number;
➢ The second bit next to the MSB of the Gray code equals the Ex-OR of the
MSB and the second bit of the binary number; it will be 0 if there are same
binary bits or it will be 1 for different binary bits;
➢ The third bit for Gray code equals the exclusive-OR of the second and third
bits of the binary number, and similarly, all the next lower-order bits follow the
same mechanism.
Example Convert (101011)2 into Gray code.
Step 1. The MSB of the Gray code is the same as the MSB of the binary number.

1 0 1 0 1 1 Binary

1 Gray

Step 2. Perform the ex-OR between the MSB and the second bit of the binary.

The result is 1, which is the second bit of the Gray code.

1 ⨁ 0 1 0 1 1 Binary

1 1 Gray
Step 3. Perform the ex-OR between the second and the third bits of the binary. The
result is 1, which is the third bit of the Gray code.

1 0 ⨁ 1 0 1 1 Binary

1 1 1 Gray
Step 4. Perform the ex-OR between the third and the fourth bits of the binary.
The result is 1, which is the fourth bit of the Gray code.
1 0 1 ⨁ 0 1 1 Binary

1 1 1 1 Gray

17
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Step 5. Perform the ex-OR between the fourth and the fifth bits of the binary.
The result is 1, which is the fifth bit of the Gray code.
1 0 1 0 ⨁ 1 1 Binary

1 1 1 1 1 Gray
Step 6. Perform the ex-OR between the fifth and the sixth bits of the binary.
The result is 0, which is the last bit of the Gray code.
1 0 1 0 1 ⨁ 1 Binary

1 1 1 1 1 0 Gray
After completing the conversion, the Gray code of binary 101011 is 111110.

Example 2.6. Convert (564)10 into Gray code.

Solution
Step 1. Convert the decimal 564 into equivalent binary.
Decimal number 564
Binary number 1000110100
Step 2. Convert the binary number into equivalent Gray code.
1 ⨁ 0 ⨁ 0 ⨁ 0⨁ 1 ⨁ 1 ⨁ 0 ⨁ 1 ⨁ 0 ⨁ 0 Binary

1 1 0 0 1 0 1 1 1 0 Gray

Conversion of Gray Code into a Binary Number


Any Gray code can be converted into an equivalent binary number by the following steps:
➢ the MSB of the binary number is the same as the MSB of the Gray code;
➢ the second bit next to the MSB of the binary number equals the Ex-OR of the
MSB of the binary number and the second bit of the Gray code; it will be 0 if there
are some binary bits or it will be 1 for different binary bits;
➢ the third bit for the binary number equals the exclusive-OR of the second bit of the
binary number and t he third bit of the Gray code, and similarly, all the next
lower-order bits follow the same mechanism.

18
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Example Convert the Gray code 101101 into a binary number.
Solution
Step 1. The MSB of the binary number is the same as the MSB of the Gray code.

1 0 1 1 0 1 Gray

1 Binary

Step 2. Perform the ex-OR between the MSB of the binary number and the second bit
of the Gray code and so on till last bit

1 0 1 1 0 1 Gray
⨁ ⨁ ⨁ ⨁ ⨁

1 1 0 1 1 0 Binary

After completing the conversion, the binary number of the Gray code 101101 is 110110
Alphanumeric
An alpha-numeric code is a binary code of a group of elements consisting of ten decimal digits.
The 26 letter of alphabets and certain number of special symbols such as #,& etc. The total number
of elements in an alpha-numeric code is greater than 36. It must be coded with the minimum of 6
bits. Two mostly used alpha-numeric code ra ASCII and EBCDIC.
ASCII (American Code for Information Interchange) Code
The ASCII code are widely used alpha-numeric code. It is basically a 7-bit code since it can create
27 = 128-bit pattern. The ASCII code can be used to encode both the lower case and upper-case
characters of alphabet and some symbol ‘#’, ‘&’ etc.
A→ 65 a→97 0→48 blank→32 and so on.
EBCDIC (Extended Binary Coded Decimal Interchange) Code
It is an 8-it alpha-numeric code. It can create 28 = 256 different bit patterns. EBCDIC cade can
encode all the symbols and characters found in ASCII code. It also encodes many other symbols
which are not encoded by ASCII code. In fact, many of the bit patterns in EBCDIC code are
unassigned.
A→193 a→129 0→240 blank → 64

19
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
Character 7-bit 8-bit
ASCII code EBCDIC code
A 1000001 11000001
B 1000010 11000010
C 1000011 11000011
D 1000100 11000100
E 1000101 11000101
F 1000110 11000110
G 1000111 11000111
H 1001000 11001000
I 1001001 11001001
J 1001010 11010001
K 1001011 11010010
L 1001100 11010011
M 1001101 11010100

Instruction Code
An instruction code is a group of bits that instruct the computer to perform the specific operations.
It is divided into two parts: op-code and operands.
The most basic part of an instruction code is its operation part called as “op-code”. The operation
code of an instruction is a group of bits that defines particular operation add, substract, multiply,
divide etc. the number of bits required for the operation code of an instruction depends on the total
number of operation available in the computer. The operation code must consist of atleast n bits
for given 2n distinct operators.
Consider a computer with 64 distinct operation. One of then is add operation. The operation code
consist of six(6) bits with the bit configuration of “110010” assigned to the add operation. When
this operation is decoded in the control unit, the computer issue control signal to reas operatnd
from memory and add operand to the processor resistance.
Solved Problems
Example Encode the following decimal numbers in BCD code:
(a) 45 (b) 273.98 (c) 62.905
Solution
(a) Decimal number is 4 5
BCD code is 0100 0101
Hence the BCD coded form of 4510 is 0100 0101

20
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
(b) Decimal number is 2 7 3 9 8
BCD code is 0010 0111 0011 1001 1000 Hence the
BCD coded form of
273.9810 is 0010 0111 0011.1001 1000

(c) Decimal number is 6 2 9 0 5


BCD code is 0110 0010 1001 0000 0101
Hence the BCD coded form of 62.90510 is 0110 0010.1001 0000 0101

Example W r i t e down the decimal numbers represented by the following BCD


codes:
(a) 100101001 (b) 100010010011 (c) 01110001001.10010010
Solution

(a) BCD code is 1 0010 1001


By padding up the first number with 3 zeros 0001 0010 1001
Decimal number is 1 2 9
Hence the decimal number is 129.
(b) BCD code is 1000 1001 0011
Decimal number is 8 9 3
Hence the decimal number is 893.
(c) BCD code is 011 1000 1001 1001 0010
By padding up the first number with 1 zero 0011 1000 1001 1001 0010
Decimal number is 3 8 9 9 2
Hence the decimal number is 389.92.
Example Encode the following decimal numbers to Excess-3 code:
(a) 38 (b) 471.78 (c) 23.105
Solution
(a) Decimal number is 3 8
BCD code is 0011 1000
Now adding 3 +0011 +0011
Excess-3 code is 0110 1011
Hence the Excess-3 coded form of 3810 is 0110 1011

21
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2

(b) Decimal number is 4 7 1 7 8


BCD code is 0100 0111 0001 0111 1000
Now adding 3 +0011 +0011 +0011 +0011 +0011
Excess-3 code is 0111 1010 0100 1010 1011

Hence the Excess-3 coded form of 471.7810 is 0111 1010 0100.1010 1011
(c) Decimal number is 2 3 1 0 5
BCD code is 0010 0011 0001 0000 0101
Now adding 3 +0011 +0011 +0011 +0011 +0011
Excess-3 code is 0101 0110 0100 0011 1000

Hence the Excess-3 coded form of 23.10510 is 0101 0110.0100 0011 1000
Example Express the following Excess-3 codes as decimal numbers:
(a) 0101 1011 1100 0111 (b) 0011 1000 1010 0100 (c) 0101 1001 0011

Solution
(a) Excess-3 code is 0101 1011 1100 0111
Subtracting 3 from each digit 0011 –0011 –0011 –0011
BCD number is 0010 1000 1001 0100
Decimal number is 2 8 9 4
Hence the decimal number is 2894.
(b) Excess-3 code is 0011 1000 1010 0100
Subtracting 3 from each digit 0011 –0011 –0011 –0011
BCD number is 0000 0101 0111 0001
Decimal number is 0 5 7 1
Hence the decimal number is 571.
(c) Excess-3 code is 0101 1001 0011
Subtracting 3 from each digit 0011 –0011 –0011

22
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
BCD number is 0010 0110 0000
Decimal number is 2 6 0
Hence the decimal number is 260.

Example Encode the following decimal numbers to Gray codes:


(a) 61 (b) 83 (c) 324(d) 456
Solution
(a) Decimal number is 61
Binary code is 111101
Gray code is 100011
(b) Decimal number is 83
Binary code is 1010011
Gray code is 1111010
(c) Decimal number is 324
Binary code is 101000100
Gray code is 111100110
(d) Decimal number is 456
Binary code is 111001000
Gray code is 100101100

Example Express the following Gray codes as binary numbers:


Solution

(a) 10111 (b) 0110101 (c) 10100011


(d) 100111100 (e) 101010001 (f ) 10110010101
a. Gray code is 10111
Binary number is 11010

Example Express the following decimal numbers as 2421 codes:


a. 168 b. 254 c. 6735 d.1973 e.9021

Solution

23
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2

(a) Decimal number given is 1 6 8


Equivalent 2421 code is 0001 1100 1110
(b) Decimal number given is 2 5 4
Equivalent 2421 code is 0010 1011 0100
(c) Decimal number given is 6 7 3 5
Equivalent 2421 code is 1100 1101 0011 1011
(d) Decimal number given is 1 9 7 3
Equivalent 2421 code is 0001 1111 1101 0011
(e) Decimal number given is 9 0 2 1
Equivalent 2421 code is 1111 0000 0010 0001

Review Questions
1. Convert the following decimal numbers to binary: 12.0625, 104 , 673.23, and 1998. 1-5.
2. Convert the following binary numbers to decimal: 10.10001, 101110.0101, 1110101.110,
1101101.111
3. Convert the following numbers from the given base to the bases indicated
(a) decimal 225.225 to binary, octal, and hexadecimal
(b) binary 11010111.110 to decimal, octal, and hexadecimal
(c) octal 623.77 to decimal, binary, and hexadecimal
(d) hexadecimal 2AC5.D to decimal, octal, and binary
4. Obtain the l’s and 2’s complement of the following binary numbers: 1010101, 0111000,
0000001, 10000, 00000.
5. Perform the subtraction with the following decimal numbers using (1) 10’s complement
and (2) 9’s complement. Check the answer by straight subtraction.
a. 5250 - 321
b. 753 – 864
c. 3570 - 2100
d. 20 – 1000
6. Represent the decimal number 8620 (a) in BCD, (b) in excess-3 code, (c) in 2, 4, 2, 1 code,
and (d) as a binary number.
7. Convert the following decimal numbers to the indicated bases.
a. 7562.45 to octal
b. 1938.257 to hexadecimal

24
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano
Number System and Codes Unit 2
c. 175.175 to binary
8. Convert the following hexadecimal number to decimal and octal numbers
a. 0FFF
b. 3FFF
9. Subtract (1010100 – 1000100) using 1’s complement.
10. Using 2’s complement, subtract (1000100-1010100).
11. Why is Gray code called the reflected code? Explain
12. What are the different types of Binary codes? Explain each in brief
13. How can you find the r’s complement using (r-1)’s complement? Explain with example
14. Excess 3 code is self-complementary code, verify the statement?
15. What do you mean by the Gray code? What are its application?
16. What is decimal code? Differentiate between BCD and excess-3 code.

Declaration: This document is prepared only for academic purposes, contents from different
sources are subject to their own copyright.

25
Compiled By: Deepesh Prakash Guragain |Unit 2 | References: Morris Mano

You might also like