Signed Number Representations
Signed Number Representations
We can represent negative numbers in decimal using the minus symbol (-). However,
since numbers are represented in computers as sequences of bits, negative numbers also need
to be represented using binary. There are three main methods of signed number representation
in binary - signed magnitude, one’s complement and two’s complement.
Signed Magnitude
Also called sign-magnitude or sign and magnitude representation. In this system the sign
of the number is represented using the most significant bit or MSB (the leftmost digit) which is
set to 0 for positive and 1 for negative. The remaining bits in the number represent the
magnitude or absolute value of the number.
A byte (8 bits) can represent numbers from -12710 to +12710, since the most significant
bit is used for the sign, the remaining seven bits (11111112) can represent a maximum absolute
value of 127. 111111112 then would represent -12710.
While this method is simple, it has many drawbacks. One problem is that there are two
possible representations of 0 in this system. For example, for an 8 bit number, both 100000002
and 000000002 can represent 010 . Another issue is that the sign has to be treated separately
in performing calculations, which can become very complex to implement in the computer’s
hardware.
One’s Complement
The one’s complement of a binary number is found by applying the bitwise NOT
operation to the number, referred to as the “complement” (inverse) of its positive representation.
This is achieved by simply inverting each bit of the number so that 1s become 0s and 0s
become 1s. For example the one’s complement of 10102 would be 01012.
This system also has the issue of having two ways of representing 0 (11111111 and
00000000 for 8-bit numbers).
Another issue is that when performing calculations with negative numbers, an additional
step is required to get the correct result. For example adding the numbers -110 and +210 using
one’s complement (using 8-bit binary numbers):
binary decimal
00000001 1 positive binary representation
11111110 –1 one’s complement
+ 00000010 +2
─────────── ──
1 00000000 0 ← Overflow bit is discarded
1 +1 ← Corrective step (add 1)
─────────── ──
00000001 1 ← Correct answer
Notice that in this calculation the initial sum had a carry bit which exceeded the 8 bit
range. This bit is discarded. While this result is accurate for those two numbers, this means that
a sum larger than 127 (for 8 bit signed numbers) cannot be represented accurately.
Two’s Complement
For example the number 4110 = 001010012 , Applying one’s complement gives:
110101102 and then adding 1 gives 110101112 which is the two’s complement representation
of that number