So far we have looked at how to represent non-negative numbers in binary form. To be more precise, we have really only looked at how
to represent non-negative integers in binary form. To represent both positive and negative integers in binary form we make use of the
leftmost bit as a sign bit. If the leftmost bit is 0, then the number is either zero or a positive integer. If the leftmost bit is 1,
then the number is negative.
The use of a sign bit does not change the way in which non-negative integers are represented. For example, the decimal number 26
would still be represented in 8-bit binary form as
00011010. To represent negative integers in binary form you might suspect
that we simply take the binary form for the corresponding positive number and change the sign bit from 0 to 1. It's not quite that
Negative integers are represented in what is called two's complement form.
To obtain the two's complement representation for
a negative integer, we begin with the binary representation of the corresponding positive integer. Then we reverse each digit (the 1s
become 0s and the 0s become 1s) and add 1 to the result.
As an example, let's determine the 8-bit binary form for the negative integer, -3. We start with the 8-bit binary form for 3, which
. Next we reverse each digit to produce
. Finally, we add 1 as shown below to obtain
Determining the decimal number represented by a two's complement binary number involves the same steps. For example, suppose you
have the 8-bit binary number
. Because the leftmost bit is 1 you know this is a negative number, but which one? To find
out you would reverse each digit to produce
and then add 1 to obtain
. This is the 8-bit binary
representation of the decimal number 73--thus our original binary number is the two's complement representation
of the decimal number -73.