0% found this document useful (0 votes)
74 views4 pages

Negative Number Representation

The document discusses different methods for representing signed numbers in computers including sign magnitude, 1's complement, and 2's complement representations. It provides examples of how to represent both positive and negative numbers using these different methods and discusses how arithmetic operations like addition and subtraction can be performed using complements.

Uploaded by

tadele766
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views4 pages

Negative Number Representation

The document discusses different methods for representing signed numbers in computers including sign magnitude, 1's complement, and 2's complement representations. It provides examples of how to represent both positive and negative numbers using these different methods and discusses how arithmetic operations like addition and subtraction can be performed using complements.

Uploaded by

tadele766
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Negative Number Representation

There are three common ways of representing signed numbers:


 Sign magnitude
 1s complement
 2s complement

Sign Magnitude Representation


Negative numbers are usually written by a minus sign in front.
Example: - (12)10, - (1100)2 e.t.c
In computer memory of fixed width, this sign is usually represented by a bit:
 0 for +
 1 for –
Example: an 8-bit number can have 1-bit sign and 7-bits magnitude.

Using this mechanism with n number of bits, we can represent:

largest negative and largest positive numbers


-(2n-1-1) to (2n-1-1)
respectively

For example using 6 bits


Lower limit: -(26-1-1)= -(25-1)= -31
Upper limit: (26-1-1)=25-1=31
Using 8 bits:
 Largest Positive Number: 01111111= +(127)10
 Lower limit is: - 0111111= -(127)10
1s Complement Notations
 Positive number is represented as unsigned number, while a negative number is represented
by taking the complement of unsigned number. We complement (change 0 to 1 and 1 to 0) an
unsigned number to obtain the negative number.
Examples: 1s complement of (00000001)2 is (11111110)1s and
1s complement of (01111111)2 = (10000000)1s
 1s representation of the number in 8-bits.
Example:
 (+14)10 = (00001110)2 = (00001110)1s. Why?
 (-14)10 = -(00001110)2 = (11110001)1s
 For 8-bits number system:
 Largest Positive Number: 01111111 -> +(127)10
 Largest Negative Number: 10000000-> -(127)10
 0 can be represented in two ways: +0 or -0
+0= 00000000
-0=11111111
 The most significant bit still represents the sign:
0 = positive
1 = negative
2s Complement
Positive numbers are represented as they are. 2s complement of an unsigned number is
obtained by inverting all the bits and adding 1 (adding 1 to1s complement of the number).
Examples:
1) 2s complement of (00000001)2 = (11111110)+1 = (11111111)2
2) 2s complement of (01111110)2 = (10000001)+1= (10000010)2
2s complement representation for 8 bit numbers:
Example:
 (+14)10 = (00001110)2 = (00001110)2s
 (-14)10 = -(00001110)2 = (11110010)2s
But, why?
Mathematical Operations Using Complements
Complement numbers can help perform subtraction. With complements, subtraction can be
performed by using addition.
Use of complements
 Complement number system is used to minimize the amount of circuitry needed to perform
integer arithmetic.
 For example, A-B can be performed by computing A + (-B), where (-B) is represented in 2s
complement of B.
Hence, the computer needs only binary adder and complementing circuit to handle both addition and
subtraction
 Signed binary numbers are of a fixed range.
 If the result of addition/subtraction goes beyond this range, overflow occurs.
 Two conditions under which overflow can occur are:
(i) positive add positive gives negative
(ii) negative add negative gives positive
1s complement Subtraction
Assume you are using n bits number for the operation. If the result is:
1) (n+1) bit number, add the (n+1)th bit to the right most side of the result
2) n bit number, the result is in 1s complement. To change the result into decimal, convert the result
into 1s complement again and add negative value before the number.

E.g. 1) 12-6. This is the same as 12+ (-6). Let us represent -6 using 1s complement using 5 bits.
6=00110  -6=11001 in 1s complement. 12=01100
12-6 01100
+11001
100101
The numbers added are 5 bit number but the result is 6 bit number. This makes condition 1 to be true
above. So add the left most bit i.e. 1 in this case, to the right most side of result.
00101
+ 1
00110
2) 6-12. this is the same as 6+(-12). Let us represent -12 using 1s complement using 5 bits.
12=01100  -12=10011 6=00110
6-12  00110
+10011
11001
The result is 5 bit number and numbers added are 5 bit numbers. This makes condition 2 to be true.
So the result is in 1s complement i.e. it is negative. To get the decimal value, change the result into
1s complement. 11001 00110 when complemented. Change 00110 into decimal adds negative
sign now. (00110)2= (6)10. Add negative sign, it will be -6. That is the result.
2s complement subtraction
Algorithm for performing A - B:
A-B = A + (-B)
 Take 2s complement of B by inverting all the bits and adding 1
 Add the 2s complement of B to A.
Assume you are using n bits number for the operation. If the result is:
1) (n+1) bit number, discard the (n+1)th bit
2) n bit number, the result is in 2s complement. To change the result into decimal, convert the result
into 2s complement again and add negative value before the number.
E.g. 1) 12-6. This is the same as 12+ (-6). Let us represent -6 using 1s complement using 5 bits.
6=00110  -6=11010 in 2s complement. 12=01100
12-6 01100
+11010
100110
The numbers added are 5 bit number but the result is 6 bit number. This makes condition 1 to be true
above. So discard the left most bit i.e. 1 in this case. The result is 00110
2) 6-12. this is the same as 6+(-12). Let us represent -12 using 1s complement using 5 bits.
12=01100  -12=10100 6=00110
6-12  00110
+10100
11010
The result is 5 bit and the added numbers are 5 bit. This makes condition 2 to be true. This shows
that the result is in 2s complemented. To get the decimal value of the result, change it into 2s
complement again. Then add negative sign.
11010  00101
+ 1
00110
(00110)2=(6)10
The result is -6.
Exercise

Choose the correct answers in the following questions.

1. Convert (63.25)10 to binary.

a, 11111.11

b,111001.01

c,111111.01

d,111111.1

e, NA

2. Convert (43.8125)10 to binary.

a,101011.1101

b,110101.1101

c,101011.1011

d,110101.1011

e, NA

3. Convert (1001011.011)2 to decimal.

a. 73.0375
b. 75.375
c. 91.375
d. 75.573
e. NA

4. Write pseudo code that reads two numbers and multiplies them together and print out their
product?

5. Write pseudo code that tells a user that the number they entered is not a 5 or a 6?

You might also like