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

Lecture9 ESC201

The document provides an overview of binary number complements, specifically 1's and 2's complements, and their applications in arithmetic operations. It explains how to compute these complements and their advantages in subtraction using adders. Additionally, it covers the representation of signed binary numbers and basic Boolean algebra operations.

Uploaded by

pmiitk2023
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 views13 pages

Lecture9 ESC201

The document provides an overview of binary number complements, specifically 1's and 2's complements, and their applications in arithmetic operations. It explains how to compute these complements and their advantages in subtraction using adders. Additionally, it covers the representation of signed binary numbers and basic Boolean algebra operations.

Uploaded by

pmiitk2023
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/ 13

ESC201: Lecture 9

Dr. Imon Mondal


ASSISTANT PROFESSOR,
ELECTRICAL ENGINEERING, IIT KANPUR

2024-25 SEM-I ESC201 INTRODUCTION TO ELECTRONICS

1
Complement of a binary number

1’s complement
Binary system:
2’s complement

1’s complement of n-bit number x is 2n -1 -x

2’s complement of n-bit number x is 2n -x

1’s complement of 1011 ? 24 − 1 − 1011 1111 − 1011 = 0100


1’s complement is simply obtained by flipping a bit (changing 1 to 0 and 0 to 1)

1's complement of 1001101 = ?

0110010
2's complement of 1010 = 1's complement of 1010+1 = 0110

2's complement of 110010 =


Leave all least significant 0’s as they are, leave first 1 unchanged and then flip all subsequent bits

001110

1011 → 0101

101101100 → 010010100
Advantages of using 2’s complement

x1 S
Adder
x2 CY

Can we carry out Y = X1 – X2 using such an adder?

x1,x2: N bit numbers


S
x1 Y = S if Sign = 0
Y = 2's Complement of S if Sign = 1 Y

Adder
2's Complement CY Sign
x2
Sign = 0 for psotive numbers
= 1 for negative numbers

2 N − x2 (CY , S ) = x1 + 2 N − x2

Note that carry will be there only if x1 – x2 is positive as 2N is N+1 bits (1 followed by N zeros)
Advantages of using 2’s complement

x1,x2: N bit numbers


S
x1 Y = S if Sign = 0
Y = 2's Complement of S if Sign = 1 Y

Adder
2's Complement CY Sign
x2
Sign = 0 for psotive numbers
= 1 for negative numbers

2 N − x2 (CY , S ) = x1 + 2 N − x2

Note that carry will be there only if x1 – x2 is positive as 2N is N+1 bits (1 followed by N zeros)

A zero carry implies a negative number whose magnitude (x2 – x1) can be found as follows:

S = x1 + 2 N − x2

2'scomplement of S = 2 N − ( x1 + 2 N − x2 ) = x2 − x1
Example

10 0100
0100
S
x1=1010 Y = S if Sign = 0
Y = 2's Complement of S if Sign = 1 Y

Adder
2's Complement CY Sign
x2=0110
Sign = 0 for psotive numbers 0
1
6 = 1 for negative numbers
1010

1010
+1010
10100
Example

6 1100
0100
S
x1=0110 Y = S if Sign = 0
Y = 2's Complement of S if Sign = 1 Y

Adder
2's Complement CY Sign
x2=1010
Sign = 0 for psotive numbers 1
0
10 = 1 for negative numbers
0110

0110
+0110
1100

It makes sense to use adder as a subtractor as well provided additional circuit required for
carrying out 2’s complement is simple
Subtraction using 10’s complement

5
x1,x2: N digit numbers 5
S
x1 Y = S if Sign = 0
Y = 10's Complement of S if Sign = 1 Y
8
Adder
10's Complement CY Sign
x2 1
Sign = 0 for psotive numbers 0
3
10-3=7 = 1 for negative numbers

This way of subtraction would make sense only if subtracting a number x2 from 10N is much
simpler than directly subtracting it directly from x1
Representing positive and negative binary numbers

One extra bit is required to carry sign information. Sign bit = 0 represents positive number
and Sign bit = 1 represents negative number
decimal Signed decimal Signed 1’s decimal Signed 2’s
Magnitude complement complement
0 0000 0 0000 0 0000
1 0001 1 0001 1 0001
2 0010 2 0010 2 0010
3 0011 3 0011 3 0011
4 0100 4 0100 4 0100
5 0101 5 0101 5 0101
6 0110 6 0110 6 0110
7 0111 7 0111 7 0111
-0 1000 -0 1111 -1 1111
-1 1001 -1 1110 -2 1110
-2 1010 -2 1101 -3 1101
-3 1011 -3 1100 -4 1100
-4 1100 -4 1011 -5 1011
-5 1101 -5 1010 -6 1010
-6 1110 -6 1001 -7 1001
-7 1111 -7 1000
If we represent numbers in 2’s complement form carrying out subtraction is same as addition

x1,x2: N bit numbers


S
x1 Y = S if Sign = 0
Y = 2's Complement of S if Sign = 1 Y

Adder
2's Complement CY Sign
x2
Sign = 0 for psotive numbers
= 1 for negative numbers

S Answer is in 2’s
x1 complement form

Adder
x2 CY

x1,x2: N bit numbers in 2's complement


Example S
x1

Adder
x2 CY

x1,x2: N bit numbers in 2's complement

0101 0101
+5 +0010 +5 +1110
+2 -2
+7 0111 +3 0011

1011 1011
-5 +0010 -5 +1110
+2 -2
-3 1101 -7 1001

2’s complement is 0011 = 3 2’s complement is 0111 = 7


Boolean Algebra

Algebra on Binary numbers


False
No
A variable x can take two values {0,1} 0
Low voltage

Basic operations:
True
AND: y = x1. x 2 Yes
1
High voltage
Y is 1 if and only if both x1 and x2 are 1, otherwise zero

x1 x2 y
0 0 0
Truth Table
0 1 0
1 0 0
1 1 1
Basic operations:

OR: y = x1 + x 2

Y is 1 if either x1 and x2 is 1. Or y= 0 if and only if both variables are zero

x1 x2 y
0 0 0
0 1 1
1 0 1
1 1 1

x y
NOT: y = x
0 1
1 0

You might also like