Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

U18EC306

Switching Theory and Logic Design


III ECE 3rd Semester
Objective of the Lecture

• This class will develop students’ knowledge on


weighted and non weighted binary codes

2
 Digital circuits in practice, are required to handle data which may be in
numeric, alphabets or special characters
 Even when the data is in the most familiar decimal form, the conservation
into binary equivalent is lengthy and cumbersome
 This requires conversion of the incoming data into binary format in a
simple manner.
 Therefore, for simple conversion of data into binary format several types of
binary codes are developed which fall under two broad categories namely,
weighted and non-weighted codes.

 Weighted binary codes


 Non weighted binary code

3
 In any weighted code, the decimal digits 0 to 9 will be represented by 10
distinct code words
 Each bit in the code word will be having specific weight
Wn…..W4 W3 W2 W1 Weights
Xn……X4 X3 X2 X1 Binary Code Word
 In order to represent the decimal numbers 0 to 9 a minimum of four bits are
required
 The corresponding decimal equivalent digit for the binary code X4 X3
X2 X1 with weights W4 W3 W2 W1 is obtained as follows.
N = X4×W4 + X3×W3 + X2×W2 + X1×W1
 When an n digit decimal number is to be converted into any weighted code,
each digit in the decimal number will be simply replaced with the
equivalent four-bit code word.

4
 Binary Coded Decimal code (BCD) code is also referred to as 8421, since
8, 4, 2 and 1 are the weights of the bits in the code word.
 The bits X4 X3 X2 and X1 in the code word will be having weights 8,4,2
and 1 respectively
8 4 2 1 Weights
X4 X3 X2 X1 BCD Code Word
 The decimal equivalent N for the BCD code word X4 X3 X2 X1 is
 N = 8 × X4 + 4 × X3 + 2 × X2 + 1 × X1 where X1 to X4 can be a 0 or 1
 Some Codes can have a combination of positive and negative weights

5
The equivalent decimal number for any code word is simply obtained by
adding the products of all the bits with their corresponding weights.
Example: the decimal equivalent of 1001 in BCD code is 1*8 + 0*4 + 0*2+ 1*1 =9
Decimal w4 w3 w2 w1
Digit 8421 2421 642–3 Invalid code words: the
0 0000 0000 0000 unused code words in a code
1 0001 0001 0101 are called invalid code words.
2 0010 0010 0010 1010, 1011, 1100, 1101, 1110
3 0011 0011 1001 and 1111 are invalid code
4 0100 0100 0100 words in BCD code
5 0101 1011 1011
6 0110 1100 0110
7 0111 1101 1101
8 1000 1110 1010
9 1001 1111 1111

The representations of some decimal numbers in the 2421 and 642 –3 codes are not
unique. For example, 4 can be represented as 1010 or 0100 in 2 4 2 1 code. 6 can
be represented as 1000 or 0110 in 642 –3 code. Such ambiguity is overcome by
adopting representation which makes the code Self complementing code

6
A code is said to be self-complementing code, if the code word of a 9s complement
of the decimal number N, can be obtained by complementing the code word of N.
A code can be Self Complementing Code if and only if the sum of the weights of
the code is exactly equal to 9.
Decimal Code
Digit 2421
0 0000
1 0001
2 1000
3 1001 All the pairs connected by arrows are
4 1010 complements of each other and their
5 0101 decimal equivalent are 9s
6 0110 complements of each other. Such a
7 0111 code is Self -Complementing Code.
8 1110
9 1111

For example, in 2421 code, the code word of the decimal number 3 is 0011.
N= 3 0011
Now, the 9s complement of the decimal number 3 is 9–3=6. The code word
of decimal 6 in 2421 is 1100 from the table. This can be simply be obtained
by complementing the code word of 3 which is 0011.

7
 Example: Convert the following decimal numbers to BCD.
1. 8234 → 1000 0010 0011 0100
2. 3421 → 0011 0100 0010 0001
3. Example: Represent the following decimal numbers using 2421 code
4. 5164 → 1011 0001 1100 0100
 Example: Convert the following BCD number to decimal
1. (110 0101.1001 01) BCD → 0110 │ 0101 . 1001│ 0100
 Example: Convert the following binary number to its equivalent BCD.

 10110112=26+0+24+23+0+21+20
 = 64+16+8+2+1
 = 9110
 =1001 0001

8
 Unlike weighted codes, the non-weighted codes do not have
any positional weights.
 There are two popularly used non-weighted codes
• Excess Code or 3 XS–3 code
• Gray code.

9
 The Excess –3 code is also called as XS–3 code. It is obtained by adding a 3, i.e.,
0011 to the code words of BCD. XS–3 code is a 4-bit code.
XS-3 is a non weighted self
complementing code

Example: Convert 3425 to XS–3 code


3425 0110 0111 0101 1000
3 4 2 5

10
 Gray code is a n bit non-weighted code which is obtained from binary code
 Bn ⊕ Bn-1 ⊕ Bn-2…⊕…..B3 ⊕ B2 ⊕ B1…….. Binary Code

 Gn Gn-1 Gn-2 G3 G2 G1 ……..Gray Code


 The MSB of the gray code is same as that of binary code.
 In order to obtain the next (second) MSB, add the 1st MSB to the 2nd MSB of the
binary code. Write the sum as the 2nd MSB of gray and discard the carry.
 Continue adding the pairs of bits of binary to obtain the remaining bits of gray code
as follows.
 Gn = Bn and Gi = Bi+1 ⊕ Bi Where Gn and Bn are MSBs
Example: Convent the binary codes (i) 10110110 and (ii)11110110
to Gray code.
(i) Binary 1 0 1 1 0 1 1 0 (ii) 1 1 1 1 0 1 1 0

Gray 1 1 1 0 1 1 0 1 1 0 0 0 1 1 0 1

11
Gray to binary code conversion
Gray Gn Gn 1 Gn2 …. G2 G1

Binary Bn Bn 1 Bn2 …. B2 B1

 The MSB of the binary is same as the MSB of gray code


 For obtaining the 2nd MSB of binary code add the 1st MSB of binary to the
second MSB of gray code. Write the sum as 2nd MSB of binary and discard
the carry.
 Continue adding the bits Bi and Gi–1 and write the sum as Bi–1 and discard the
carry.
Example: Convert the gray code 11011011 to binary.
Gray 1 1 0 1 1 0 1 1

Binary 1 0 0 1 0 0 1 0

12
Decimal Binary Gray
Distance: The distance between
(4 Bit) (4 Bit)
any two code words is defined as
0 0000 0000 the number of positions in which
1 0001 0001 the two code words differ.
2 0010 0011
3 0011 0010
Cyclic Code: A code in which
4 0100 0110
each code word differs from the
5 0101 0111
successive or preceding code
6 0110 0101
word only by one position is
7 0111 0100
called as Cyclic code.
8 1000 1100
9 1001 1101 Gray code is a Cyclic code
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000

13
𝟐 𝐛𝐢𝐭 𝟐 𝐛𝐢𝐭 𝟑 𝐛𝐢𝐭 𝟒 𝐛𝐢𝐭
𝐁𝐢𝐧𝐚𝐫𝐲 𝐆𝐫𝐚𝐲 𝐆𝐫𝐚𝐲 𝐆𝐫𝐚𝐲
00 00 000 0000
Reflecting Code : A code is
01 01 001 0001
called Reflecting Code if ‘n’ bit
10 11 011 0011
code can be obtained by
11 10 010 0010 reflecting (n-1) bit code.
110 0110
111 0111
101 0101 Gray code is also a reflecting
100 0100 code
1100
1101
1111
1110
1010
1011
1001
1000

14
 BCD numbers are added applying binary addition. However, after addition if any of
the nibbles in the resultant sum is invalid, ie greater than 9 (1001) or a carry is
generated from that stage, then 6 (0110) must be added to the sum to bring the
result to valid form

 Example1: Add 2394 and 3676 in BCD


2394 0010 0011 1001 0100
3676 0011 0110 0111 0110
1 Nibble Carry
6070 0101 1010 0000 1010 3nibbles are invalid BCD code
0110 0110 0110 0110 is added
0110 0000 0111 0000 BCD
6 0 7 0 Decimal

Assignment:
(i) Add 476 and 945 in BCD
(ii) Add 734 and 98 in BCD

15
 BCD numbers are subtracted applying binary subtraction. However, after
subtraction if any of the nibbles in the resultant difference is invalid, ie greater than
9 (1001) or a borrow is taken by that stage, then 6 (0110) must be subtracted from
the difference to bring the result to valid form

Example: Subtract 9217–1936 in BCD

9217 1001 0010 0001 0111


–1936 –0001 1001 0011 0110
7281 0111 1000 1110 0001 3nibbles are invalid BCD
–0110 –0110 0110 is subtracted
0111 0010 1000 0001 BCD
7 2 8 1 Decimal

Assignment:
(i) Subtract 976 and 595 in BCD
(ii) Subtract 734 and 98 in BCD

16
 Self learning question :
 How many self complementing codes exist with positive
weights?

 Self learning topic: XS-3 addition and subtraction

17
Outcome of the Lecture

• Having listened to this lecture you should be


able to represent decimal numbers using
weighted and non weighted binary codes

18
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
KAKATIYA INSTITUTE OF TECHNOLOGY & SCIENCE, WARANGAL
(An Autonomous Institute under Kakatiya University, Warangal)

Assignment- WEEK-2
(UNIT – I)

Topic : Binary arithmetic and Codes


Class : B.Tech. III-Semester
Section : ECE
Code-Subject : U18EC306 –Switching Theory and Logic Design
Assignment posted on : 09.08.2020 (SUNDAY)
Assignment Submission Due : 16.08.2020 (SUNDAY)
Correction & Posting of Marks : 23.08.2020 (SUNDAY)
Max. Marks: 10
WEEK-2, Assignment-2: In this assignment, you will use your knowledge of the Number
systems to answer the following questions. These are the follow-up questions on the concepts
to be discussed in the classes during week-1

Class Q. Answer the following questions. CDLL CO


No
Class-1 1. Find the signed magnitude form of -63 [1] [R] CO 1
2. Simplify the following numbers using 1’s and 2’s [2] [An] CO 1
complement method
(i) (1011001)2 – (0110110)2
(ii) (10001001)2 – (10101100)2
Class-2 3. Find the Excess-3 code for (364)10 [1] [R] CO 1
4. Construct gray code for the following numbers [2] [Ap] CO 1
(i) (10101010)2
(ii) (10111111)2
Class-3 5. Find the binary code for (10000101)gray [1] [R] CO 1
6. Simplify the following BCD numbers [3] [An] CO 1
(i) 24 + 18
(ii) 24 – 56

V.Raju
Assistant Professor
Dept. of ECE
Thank you!!!!!

Kosaraju Sivani 13-08-2020 20

You might also like