0% found this document useful (0 votes)
38 views26 pages

Representation of Negative Numbers and

This document discusses different methods for representing negative numbers in digital circuits, including signed magnitude representation, one's complement representation, and two's complement representation. Signed magnitude representation uses the most significant bit to indicate sign, but has drawbacks like multiple representations for zero. One's complement representation complements all bits to represent negative numbers, but still has multiple zero representations. Two's complement representation, which is the preferred method, complements and adds one to represent negative numbers, avoiding the issues of the other methods.

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)
38 views26 pages

Representation of Negative Numbers and

This document discusses different methods for representing negative numbers in digital circuits, including signed magnitude representation, one's complement representation, and two's complement representation. Signed magnitude representation uses the most significant bit to indicate sign, but has drawbacks like multiple representations for zero. One's complement representation complements all bits to represent negative numbers, but still has multiple zero representations. Two's complement representation, which is the preferred method, complements and adds one to represent negative numbers, avoiding the issues of the other methods.

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

Digital Circuit Design

18B11EC215

Lecture3

Representation of Negative Numbers and


Complements

1
Outline
■ Unsigned Binary Numbers
■ Signed Magnitude Representation
■ Diminished Radix/One’s complement Representation/r-1’s
■ Radix/Two’s Complement Representation/r’s

2
UNSIGNED BINARY NUMBERS
■ In some applications, data is either positive or negative.

■ We concentrate on absolute value or magnitude only.

■ Data is called unsigned binary because all bits are used to represent magnitude
of the corresponding decimal only.

3
Signed Integer Representation[2]
■ We have been ignoring signed integers.
■ The PROBLEM with signed integers ( - 45, + 27, -99) is the SIGN!
■ How do we encode the sign?
■ The sign is an extra piece of information that has to be encoded in addition to
the magnitude.

4
What can we do?[1,2]
Following are the three possible techniques

■ Signed Magnitude Representation


■ Diminished Radix-Complement Representation
■ Radix-Complement Representation

5
Signed Magnitude Representation[2]
■ Signed Magnitude (SM) is a method for encoding signed integers.
■ The Most Significant Bit (MSB) is used to represent the sign.
■ ‘1’ is used for a ‘-’ (negative sign),
■ ‘0’ for a ‘+’ (positive sign).

6
Format of SM Representation[2]

■ The format of a SM number in 8 bits is:


smmmmmmm
■ Where ‘s’ is the sign bit
■ The other 7 bits represent the magnitude.
■ NOTE: for positive numbers, the result is the same as the unsigned binary
representation.

7
Signed Magnitude Ex. (8 bits)[2]
■ -5 = (1 0000101)2 = (85)16
■ +5 = (0 0000101)2 = (05)16
■ +127 = (0 1111111)2 = (7F)16
■ -127 = (1 1111111)2 = (FF)16
■ +0 = (0 0000000)2 = (00)16
■ -0 = (1 0000000)2 = (80)16

8
■ For N bits, can represent the signed integers
- {2(N-1) – 1} to {+ 2(N-1) – 1}
■ For 8 bits, can represent the signed integers -127 to +127.
■ Signed magnitude is easy to understand and encode.
■ Simple.
■ Negative numbers are identical to positive numbers except the sign bit.
■ Used today in some applications.

9
Problems with Signed Magnitude
Representation[2]

■ One problem is that it has two ways of representing 0 (-0,and +0)


■ Another problem is that addition of
K + (-K) does not give Zero!
■ -5 + 5 = (85)16 + (05)16 = (8A)16
■ Requires complicated arithmetic circuits.

10
One’s Complement Representation[2]

■ One’s complement is another way to represent signed integers.


■ To encode a negative number, get the binary representation of its
magnitude, then COMPLEMENT each bit.
■ Complementing each bit mean that 1’s are replaced with 0’s, 0’s are
replaced with 1’s.

11
Example[2]
■ How is -5 represented in One’s Complement (encoded in 8 bits) ?
The magnitude 5 in 8-bits is
( 00000101)2 = (05)16
■ Now complement each bit:
(11111010)2 = (FA)16
■ (FA)16 is one’s complement representation of -5.

12
One’s Complement Examples
■ +5 = (00000101)2 = ( 05 )16
■ -5 = (11111010) = ( FA )16
■ +127 = (01111111)2 = ( 7F )16
■ -127 = (10000000)2 = ( 80 )16
■ +0 = (00000000)2 = ( 00 )16
■ -0 = (11111111)2 = ( FF )16

13
■ For N bits, can represent the signed integers
- {2(N-1) – 1} to + {2(N-1) – 1}
■ For 8 bits, can represent the signed integers -127 to +127.

14
Limitations of One’s Complement Method
■ Still have the problem that there are two ways of representing 0 (-0, and +0)
■ Mathematically speaking, no such thing as two representations for zeros.
■ However, addition of K + (-K) now gives Zero!
-5 + 5 = ( FA )16 + ( 05 )16
= ( FF)16
= -0 !!!

15
■ Unfortunately, K + 0 = K only works
if we use +0,
■ Does not work if we use -0.
■ 5 + (+0) = (05)16 + (00)16 = (05)16 = 5 (ok)
■ 5 + (-0) = (05)16 + (FF)16= (04)16 = 4 (wrong)

16
Two’s Complement Representation[2]
■ Two’s complement is another way to represent signed integers.
■ To encode a negative number, get the binary representation of its magnitude,
COMPLEMENT each bit, then ADD 1.
or
■ See 1 from LSB , mark it and complement all bits which are occurring before it.

17
Example[2]
■ What is -5 in Two’s Complement, 8 bits?

■ The magnitude 5 in 8-bits is:

(00000101)2 = (05)16
■ Now complement each bit:
(11111010)2 = (FA)16
■ Now add one: (FA) 16 + 1 = (FB)16

■ (FB)16 is the 8-bit, two’s complement


representation of -5.

18
Two’s Complement Examples
■ -5 = ( 11111011) = ( FB)16

■ +5 = ( 00000101 )= ( 05)16

■ +127 = ( 01111111) = (7F)16


■ -127 = ( 10000001) = ( 81)16
■ -128 = ( 10000000 )= ( 80 )16
■ +0 = ( 00000000) = (00)16

■ -0 = ( 00000000) = (00 )16 (only 1 zero!!!)

19
■ For N bits, can represent the signed integers
-2(N-1) to + 2(N-1) - 1
■ Note that negative range extends one more than positive range.
■ For 8 bits, can represent the signed integers -128 to +127.

20
Two’s Complement Comments
■ Two’s complement is the method of choice for representing signed integers.
■ It has none of the drawbacks of Signed Magnitude or Ones Complement.
■ There is only one zero, and K + (-K) = 0.
-5 + 5 = (FB)16 + ( 05)16 = (00)16 = 0 !!!
■ Normal binary addition is used for adding numbers that represent two’s complement
integers.

21
Complements[3]
■ 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.

22
The r’s complement[3]
and with n number of digits
■ Given a positive number N in base r with and integer part of n digits, the r’s
complement of N is defined as :

(rn) – N for N ≠ 0
0 for N=0

23
Examples
■ 10’s complement of (36360)10 = 105 – 36360

Note: Here n= 5

Ans : 63640

■ 10’s complement of (0.3534) 10


= 100 – .3534

Note: Here n= 0

Ans : 0.6466

■ 10’s complement of (25.353) 10


= 102 - 25.353

Note: Here n= 2

Ans : 74.361
24
Examples[1]
■ The 2’s complement of (101100)2
= (26)10 - (101100)2= (1000000-101100)2=010100

■ The 2’s complement of (0.101)2


= (20)10 - (.101)2=0.011

Note: In general the 2’s complement can be formed by leaving all significant zeros
and the first nonzero digit unchanged, and then replacing 1’s by 0’s and 0’s by
1’s in all other higher significant digits.

25
References

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

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

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

26

You might also like