Subtractionusing 1 Scomplement

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

Subtraction using

complements&
CODES:
Lecture 4
Jeevan Battini
Objective of Lecture 4:
• The lecture will develop students’ knowledge on subtraction using
complements, BCD arithmetic and binary Codes

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 2


Signed Magnitude Representation

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 3


Carefully observe the differences in three methods.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 4


The range of numbers

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 5


Subtraction Using 1’s Complement
• The Before using any complement method for subtraction equate the length
of both minuend and subtrahend by introducing leading zeros.
• Following are the rules for subtraction using 1’s complement.
• Take 1’s complement of subtrahend.
• Add 1’s complement of subtrahend to minuend.
• If a carry is produced by addition then add this carry to the LSB of result. This is called
as end around carry (EAC).
• If no carry, generated result is negative, and again do 1’s complement, put –ve sign.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 6


Example 1
• Perform following subtraction using 1’s complement.
•7–3

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 7


Example 2:
• 3-7

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 8


2’s complement Subtraction
• Take 2’s complement of subtrahend.
• Add 2’s complement of subtrahend to minuend.
• If a carry is produced, then discard the carry and the result is
positive.
• If no carry is produced result is negative and is in 2’s compliment
form.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 9


• Perform following subtraction using 2’s complement.
•7–5

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 10


Example 2:
• 5-7

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 11


9’s and 10’s Complement
• 9’s complement of 36 ?

• 10’s complement of a decimal number can also be obtained by


adding 1 to its 9’s complement.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 12


r’s Complement and (r – 1)’s Complement
• r stands for radix or base of the number system
• r’s complement is referred as radix complement and (r – 1)’s
complement is referred as diminished radix complement.
• Examples of r’s complements are 2’s complement and 10’s
complement.
• Examples of (r – 1)’s complement are 1’s complement and 9’s
complement.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 13


CODES
• Binary Coded Decimal (BCD)
• The BCD is a group of four binary bits that represent a decimal digit.
• In this representation each digit of a decimal number is replaced by a 4-bit
binary number (i.e., a nibble).
• Since a decimal digit is a number from 0 to 9.
• a nibble representing a number greater than 9 is invalid BCD.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 14


Carefully observe the difference : binary and BCD

• The rules for binary subtraction is summarized.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 15


BCD Addition
• Adder circuits used are simple binary adders, which does not take
care of peculiarity of BCD representation.
• Thus one must verify the result for valid BCD by using following
rules:
1. If Nibble (i.e., group of 4-bits) is less than or equal to 9, it is a valid BCD
number.
2. If Nibble is greater than 9, it is invalid. Add 6 (0110) to the nibble, to
make it valid. Or
If a carry was generated from the nibble during the addition, it is
invalid. Add 6 (0110) to the nibble, to make it valid.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 16


BCD Addition
• Example

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 17


BCD Addition
• Example

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 18


BCD Subtraction
• The best way to cary out the BCD subtraction is to use
complements - 9’s and 10’s complement
• Add the 10’s complement of subtrahend to minuend.
• Apply the rules of BCD addition to verify that result of addition is valid
BCD.
• Apply the rules of 10’s complement on the result obtained in step 2, to
declare the final result i.e., to declare the result of subtraction.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 19


Subtract 61 from 68 using BCD.
• first we perform the subtraction using 10’s complement in decimal
system. After that we go for BCD subtraction.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 20


Weighted & Non-weighted codes
• Effect In weighted binary codes, each position of a number represents a specific weight.
• The bits are multiplied by the weights indicated; and the sum of these weighted bits gives
the equivalent decimal digit.
• Examples: 8421, 84-2-1, 2421.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 21


Non-Weighted Codes
• Excess-3 codes and Gray codes are examples of non-weighted
codes.

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 22


Gray Code:

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 23


Binary to Gray Code conversion and vice versa
• Convert binary 100101 to Gray code word.?
• Ex-OR operation
• Two bits are same; output is 0
• Two bits are different; output is 1

• Ans: 110111
• Convert Gray code word 100111 into binary.?

• Ans: 111010
9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 24
Self Learning
• Self learning question.
• Why is 2’s complement subtraction is advantageous over 1’s complement?
• Self learning topic
• Excess -3 Addition/subtraction

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 25


Outcome of Lecture 4
• After Completion of the session, the students will be able to…

• subtraction using 1’s and 2’s complement.


• Compute BCD addition and subtraction
• List the types of CODEs.
• Convert binary to gray and gray to binary .

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 26


Week2_Assignment

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 27


Next Session:
• Boolean Algebra
• New concepts

THANK YOU ….Students

9/5/2022 U18EI309: Digital Electronics (CSE-3) - Jeevan Battini 28

You might also like