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

Complements of Numbers

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 views18 pages

Complements of Numbers

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/ 18

CS/ECE/EEE/INSTR F215:Digital Design

Lecture 03: Complements of numbers


Thu, 08 Aug 2024
BITS Pilani R. N. Ponnalagu, EEE
Hyderabad Campus
Complements of Numbers

To simplify subtraction operation Less expensive circuits to


Logical manipulation implement the operations

Types of
Complements

Diminished Radix Radix Complement


Complement (r’s complement)
((r-1)’s complement)

Ex. 9’s, 1’s, 7’s and 15’s Ex. 10’s, 2’s, 8’s and 16’s
Radix (r) / base complement

Given a number N in base r having ‘n’ digits, r’s complement is defined as (rn - N)

➢ In case of decimal it is called 10’s complement


10’s complement of 865 is N = 865 , n = 3 (digits) and r = 10
103 - 865 = 1000 - 865 = 135

➢ In case of binary it is called 2’s complement


2’s complement of 1011 is N = 1011, n (no. of bits) = 4, r = 2
24 - 1011 = (16)10 – 1011 = (10000)2 - 1011 = 0101
Diminished Radix Complement ➔(r-1)’s complement

➢ Given a number 𝑁 in base 𝑟 having 𝑛 digits (𝑟 − 1)’s complement is defined as


(𝒓𝒏 − 𝟏 − 𝑵)
➢ In case of decimal, it is called 9’s complement

Example : 9’s complement of 865 is: 103 -1 - 865 = 999 - 865 = 134

In case of binary it is called 1’s complement


Example : 1’s complement of 1011 is:

(24 - 1) - 1011 = (10000 – 1) – 1011 = 1111 - 1011 = 0100

Simple way of 1’s complement : Toggle all the bits

1’s complement of 1011 is: 0100 (Toggle all the bits)


Complements of Numbers
10’s complement = 9’s complement + 1

2’s complement = 1’s complement + 1


(OR)
Toggle all the bits to the left of the first “1” from the right

➢ 2’s complement of 1011 is 24 -1011 = 10000-1011 = 0101


(using formula)

➢ 2’s complement of 1011 is 0100 + 1 = 0101


(using 1’s complement of 1011 + 1)

➢ 2’s complement of 1011 is 0 1 0 1


(using simple trick)
Complements of Numbers

Addition 7+3
7 → 0111
3 → 0011

1 1 1
0 1 1 1
0 0 1 1
1 0 1 0
1010 → (10)10
Complements of Numbers
Subtraction using 2’s complement 7-3
7 → 0111 0111
3 → 0011 2’s complement 1101

1 1 1 1
0 1 1 1
1 1 0 1

0 1 0 0
Carry generated
and discard it
0100 → (4)10
Complements of Numbers

Subtraction using 2’s complement 3-7

3 → 0011 0011
7 → 0111 2’s complement 1001

0 0 1 1
0 0 1 1
1 0 0 1

1 1 0 0
No carry

1100 → ?
Complements of Numbers

If final Carry not generated 1100


Answer is = -(2’s complement of result)
= -(2’s complement of 1100)
= -(0100)2

= -(4)

If final carry generated then Answer = result of addition

If final carry NOT generated then Answer = -(2’s complement of result of addition)
Signed Numbers

Need for notation to represent negative numbers

MSB 1 indicates negative


MSB 0 indicates positive

Representation of negative numbers

(1) Signed magnitude representation

(2) Signed 1’s complement representation

(3) Signed 2’s complement representation (widely used)


Signed numbers (4-bits)
Decimal Signed Signed 1’s Signed 2’s
Number magnitude complement complement
+0 0000 0000 0000
+1 0001 0001 0001
+2 0010 0010 0010
+3 0011 0011 0011
+4 0100 0100 0100
+5 0101 0101 0101
+6 0110 0110 0110
+7 0111 0111 0111
If MSB 0 same value as binary
Signed numbers (4-bits)
Decimal Number Signed Magnitude

-0 1000
-1 1001
-2 1010 MSB indicates sign
rest of the bits indicate magnitude
-3 1011
-4 1100
Two representations for 0
-5 1101
(+0 and –0)
-6 1110
-7 1111
Signed numbers (4-bits)
Decimal Positive Positive
Number representation representation Signed 1’s complement
in decimal in binary (Toggle all the bits)

-0 +0 0000 1111
-1 +1 0001 1110
-2 +2 0010 1101
-3 +3 0011 1100
-4 +4 0100 1011

-5 +5 0101 1010
Two representations
-6 +6 0110 1001 for 0
(+0 and –0)
-7 +7 0111 1000
Signed numbers (4-bits)
Decimal Positive Positive
Number representation representation Signed 2’s complement
in decimal in binary (1’s complement +1)

-0 +0 0000 0000
-1 +1 0001 1111
-2 +2 0010 1110
-3 +3 0011 1101
-4 +4 0100 1100
-5 +5 0101 1011
-6 +6 0110 1010
-7 +7 0111 1001
-8 1000
Signed numbers (4-bits)

4-bit unsigned number has range 0 to 15

Ranges for signed numbers n-bit

4-bit signed magnitude -7 to +7 -(2n-1 - 1) to + (2n-1 – 1)

4-bit signed 1’s complement -7 to +7 -(2n-1 – 1) to + (2n-1 – 1)

4-bit signed 2’s complement -8 to +7 - 2n-1 to + 2n-1 – 1


Problems
(1) Represent +51 in

(i) Signed Magnitude


(ii) 1’s complement and
(iii) 2’s complement with minimum no. of bits

Ans: Signed Magnitude/1’s complement/2’s complement of Positive number

0 1 1 0 0 1 1
Problems
(1) Represent -51 in

(i) Signed Magnitude


(ii) 1’s complement and
(iii) 2’s complement with minimum no. of bits
(Ans) Signed Magnitude
1 1 1 0 0 1 1

(Ans) 1’s complement

1 0 0 1 1 0 0

(Ans) 2’s complement

1 0 0 1 1 0 1

You might also like