Pages

Categories

Representing Negative Numbers in Binary

Representing Negative Numbers in Binary
Published on 12 December, 2013
Binary is the fundamental number system used on computers, as it provides a way to denote if some thing is “on”, or “off”. Binary can also be referred to as the base two number system, where we humans commonly use base ten throughout our lives.
Unsigned
To represent positive whole numbers in binary can be done like so using 3 bits of data:
Binary Decimal
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7
This method of representing numbers in binary is known as unsigned because there is no way to have a negative value, only positive.
Signed and Magnitude
This next method is called signed and magnitude where the binary numbers are split in half; one half for positive values, the other for negative values. A negative value is denoted by having the first bit be a 1. Like so:
Binary Decimal
000 0
001 1
010 2
011 3
100 -0
101 -1
110 -2
111 -3
However the problem with using this method of representing negative values is that there are two 0′s, a positive 0 and a negative 0.
Ones’ Complement
Another way to represent negative numbers is by using one’s complement, where to get the negative value, the bits are simply flipped, like so:
Binary Decimal
000 0
001 1
010 2
011 3
100 -3
101 -2
110 -1
111 0
However similarly to signed and magnitude method of representing negative numbers, there are still two 0′s, positive and negative.
Twos’ Complement
A way to solve the previous issues of having two 0 values, twos’ complement is used. This method has the same step as ones’ complement where the bits are flipped, but then it has an additional step of adding one.
Binary Decimal
000 0
001 1
010 2
011 3
100 -4
101 -3
110 -2
111 -1
This solves the previous problem of having two 0 values.
Notes:
For every n number of bits, there are 2^n possible values. So in this three bit number system, there are 2^3 which equals 8 possible values.
Filed in Computer Science Revision | No replies