0% found this document useful (0 votes)
76 views20 pages

Complements and Codes

This document provides an overview of digital codes and complements. It discusses (r-1)'s complements and r's complements, and how they are used for subtraction. It also covers various binary codes like binary code, binary coded decimal (BCD) code, excess-3 code, and Gray code. Examples are provided to demonstrate how values are represented using these codes and complements. References are listed at the end for additional reading.

Uploaded by

Gautam
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)
76 views20 pages

Complements and Codes

This document provides an overview of digital codes and complements. It discusses (r-1)'s complements and r's complements, and how they are used for subtraction. It also covers various binary codes like binary code, binary coded decimal (BCD) code, excess-3 code, and Gray code. Examples are provided to demonstrate how values are represented using these codes and complements. References are listed at the end for additional reading.

Uploaded by

Gautam
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
You are on page 1/ 20

Digital Circuit Design

18B11EC215
Lecture 4
Complements and Codes

1
Outline
■ Complements
■ (r-1)’s (Diminshed Radix) complement
■ Subtraction using r’s complement
■ Subtraction using (r-1)’s complement
■ What are codes used for?
■ Binary Codes
■ BCD Codes
■ Excess-3 Codes
■ Gray Codes
■ Alphanumeric codes

2
Complements[1]
■ Complements are used in digital computers for simplifying the subtraction operation
and for logical manipulation.

■ There are two types of complements for each base-r system:


(1) The r’s complement. E.g. 2’s complement for binary and 10’s complement for
decimal.

(2) The (r-1)’s complement. E.g. 1’s complement for binary and 9’s complement for
decimal.

3
The (r-1)’s Complement[1]
■ Given a positive number N in base r with an integer part of n digits and a
fraction part of m digits, the (r-1)’s complement of N is defined as :

( rn – r-m)10 – N for N ≠ 0

4
Examples

■ The 9’s complement of (36360)10


here n = 5 & m = 0
= (105 – 1 – 36360)
= 99999-36360
= 63639

■ The 9’s complement of (25.3636)10


here n = 2 & m = 4
= (102 -10-4 - 25.3636)
=74.6363

Note: From observation it can be seen that 9’s complement of a decimal number
is formed by simply subtracting every digit from 9.

5
Example
■ The 1’s complement of (101100)2
Here n= 6 and m=0

= (26-20)10 – (101100)2 =(111111 – 101100)2


= (010011)2
Note: From observation it can be seen that 1’s complement of a binary number
is formed by simply changing 1’s to 0 and 0’s to 1’s.

6
Subtraction using r’s complements[2]
Rules for Subtraction using r’s complement:
Subtraction can be done by adding the minuend X to the r’s complement of the
subtrahend Y. Inspect the result obtained for an end carry.

Case 1. If after addition ,final carry is generated.


▪ Answer is positive
▪ Discard the carry
▪ Real answer is given by the remaining bits

Case 2. If after addition ,final carry is not generated.


▪ Answer is negative
▪ Real answer is given by again taking the r’s complement of the answer

7
Example[1]
Subtract using 10’s complement.
(a) X-Y (b)Y-X
Given
X = 72532 and Y= 3250
Ans :(a)
Step 1: Make the number of digits in both numbers equal
X = 72532 and Y= 03250
Step 2 :
72532
+ 96750 ( 10’s complement of Y)
1 69282

end carry is there which can be discarded.


Answer : 69282

8
■ (b) Subtract 3250 – 72532

10’s complement for Y is 27468


So 03250
+ 27468
_____________
30718 (no carry)

So answer will be –(10’s complement of 30718)= -69282

9
Example[1]

Given X= 1010100 and Y= 1000011, perform the subtraction (a) X-Y (b) Y-X using
2’s complement(a)
Ans : (a)
2’s complement for Y is 0111101
So 1010100
+ 0111101
_____________
10010001

Discard end carry, So answer will be 0010001.

10
(b) Y= 1000011 X= 1010100
Ans :
1000011
+ 0101100
_____________
1101111

No end carry, Take 2’s complement of answer and put –ve sign.

■ So answer will be -0010001.

11
Subtraction using (r-1)’s complement[2]
Rules for Subtraction using (r-1)’s complement:
Subtraction can be done by adding the minuend X to the (r-1)’s complement
of the subtrahend Y. Inspect the result obtained for an end carry.

Case 1. If after addition ,final carry is generated.


▪Answer is positive
▪Add the carry to the remaining bits(end-around carry)
▪Real answer is given by after adding this carry to the remaining bits

Case 2. If after addition ,final carry is not generated.


▪Answer is negative
▪Real answer is given by again taking the (r-1)’s complement of the answer

12
Example[1]
Subtract using 9’s complement.
(a) X-Y (b)Y-X
Given
X = 72532 and Y= 3250
Ans :(a)
Step 1: Make the number of digits in both numbers equal
X = 72532 and Y= 03250
Step 2 :
72532
+ 96749 ( 9’s complement of Y)
1 69281
+1 end-around carry
69282

Answer : 69282

13
(b) Subtract 3250 – 72532
X=03250 Y=72532
9’s complement for Y is 27467
So 03250
+ 27467
_____________
30717 (no carry)

So answer will be –(9’s complement of 30717)= -69282

14
Codes[1,2,3]
■ Code is a systematic arrangement of symbols in a specific manner to perform
operations.
■ Various codes are used to represent data which may be numeric, alphabets or
special characters.
■ Computer and other digital circuits process data in the binary formats.
■ A user must be very careful about the code being used while interpreting
information available in the binary format.
■ Codes are mainly divided into two types :
(i) Weighted Code – Codes in which each bit of the number has fixed
weight. Example BCD Code
(ii) Non weighted Codes- Codes in which no fixed weight is attached to the bits.
Example Gray Code, Excess 3 code.

15
Example

■ (1000001)2 represents (65)10 in Decimal.


■ (1000001)2 represents (41)BCD in BCD.

16
Binary Codes[1]

■ One binary bit can take on values 0,1.


■(65) in binary can be represented by 1000001.
10
■ We can represent Two values:

True = 1, False = 0
On = 1 , off = 0
■Two Binary digits (two bits) can take on values of 00, 01, 10, 11.

■Three Binary digits (three bits) can take on values of 000, 001, 010, 011, 100, 101,
110, 111. We can represent 8 values

N bits can represent 2N different values.(for example, 4 bits can represent 24 or 16


different values)N bits can take on unsigned decimal values from 0 to 2 N-1.

17
BCD Codes[2]
■ In these codes, decimal digit 0 through 9 are represented by their
natural binary equivalents using four bits and each decimal digit of a
decimal number is represented by this four bits code individually.

■ It is also known as 8,4,2,1 code.

■ Only 10 of the 16 possible 4 –bit binary code groups are used, rest of
the 6 code groups are unused(1010, 1011,1100,1101,1110,1111).

18
Example
Convert following numbers into BCD Code.
■(23) is represented by (0010 0011)BCD
10

(08)10 is represented by (0000 1000)BCD


■ (921)10 is represented by (1001 0010 0001)BCD

19
References

[1] M. Morris Mano and Michael D. Ciletti, “Digital Design with an Introduction to the
Verilog HDL,” 5th Edition, Pearson Education,2013.

[2] Reshu Gupta, Amit Gupta ,Atul Kumar Sharma “ Switching Theory(Digital
Electronics)”, Tech India Publication Series, Satya Prakashan, New Delhi.

[3] R. P. Jain, “Modern Digital Electronics,” 4th Edition, Tata McGraw-Hill Education,
2009.

20

You might also like