Binary Words vs. Integers

In class we have covered four different ways to represent integers using binary words. (or, another way to put this, we have learned four different ways to encode integers into binary words). Still another way to say this is that we have learned four different ways to interpret binary words as integers (or, we have learned four different ways to decode binary words into integers).

The four different representations (i.e., encodings) of integers (or, the four different interpretations (i.e., decodings) of binary words) are called unsigned integer, signed magnitude, 2s complement, and biased.

As far as C/C++ or Java programming is concerned, the unsigned integer and 2s complement encodings are the most important since the unsigned int data type uses the unsigned integer encoding and the int data type uses the 2s complement encoding. The signed magnitude encoding is not used in any modern computer (though something like it is used in floating point numbers). The biased encoding is used for the exponents in floating point numbers.

There are two tables below that summarize these representations (or interpretations) using a 4-bit binary word. The first table emphasizes the point of view that we are looking at ways to interpret (or decode) binary words.

Binary
Word
Unsigned integer
Interpretation
Signed magnitude
Interpretation
Twos complement
Interpretation
Biased
Interpretation
0000 0 +0 0 -7
0001 +1 +1 +1 -6
0010 +2 +2 +2 -5
0011 +3 +3 +3 -4
0100 +4 +4 +4 -3
0101 +5 +5 +5 -2
0110 +6 +6 +6 -1
0111 +7 +7 +7 0
1000 +8 -0 -8 +1
1001 +9 -1 -7 +2
1010 +10 -2 -6 +3
1011 +11 -3 -5 +4
1100 +12 -4 -4 +5
1101 +13 -5 -3 +6
1110 +14 -6 -2 +7
1111 +15 -7 -1 +8

The second table emphasizes the point of view that we are looking at ways to represent (or encode) integers as binary words. Notice that the second table also shows us what part of the number line is encoded by each encoding. Each of the four methods represents a different segment of the number line.

With four bits, we have 16 different binary words to make use of, so we can represent (or, encode) at most 16 different integers, but not all of the encodings manage to represent this maximum number of integers.

IntegerUnsigned integer
Representation
Signed magnitude
Representation
Twos complement
Representation
Biased
Representation
+15 1111 ---- ---- ----
+14 1110 ---- ---- ----
+13 1101 ---- ---- ----
+12 1100 ---- ---- ----
+11 1011 ---- ---- ----
+10 1010 ---- ---- ----
+9 1001 ---- ---- ----
+8 1000 ---- ---- 1111
+7 0111 0111 0111 1110
+6 0110 0110 0110 1101
+5 0101 0101 0101 1100
+4 0100 0100 0100 1011
+3 0011 0011 0011 1010
+2 0010 0010 0010 1001
+1 0001 0001 0001 1000
0 0000 0000 or 1000 0000 0111
-1 ---- 1001 1111 0110
-2 ---- 1010 1110 0101
-3 ---- 1011 1101 0100
-4 ---- 1100 1100 0011
-5 ---- 1101 1011 0010
-6 ---- 1110 1010 0001
-7 ---- 1111 1001 0000
-8 ---- ---- 1000 ----