
Unfortunately, it is difficult to look at hundreds of zeroes and ones and have them make any sense. They all seem to blend into one another unless we can organize them in some useful way. The most common way to organize bits is by grouping them into "halfbytes," or 4bit, chunks. Then, each of those 16 possible patterns of 0/1 are represented by a hexadecimal digit in the range of 0F, as shown in the table.
By using the hexadecimal system, it is easy to write long strings of bits in a compact form. For example,
110101110010101011010010110101100011010111111simply causes one's eyes to water. But let's break it up into 4bit chunks, starting from the rightmost bit:
Notice that there are not enough bits for the leftmost group to be complete. We will simply pad it with some extra zeroes:
1 1010 1110 0101 0101 1010 0101 1010 1100 0110 1011 1111
Next, we determine the hex digit for each of the groups:
0001 1010 1110 0101 0101 1010 0101 1010 1100 0110 1011 1111
Thus, the binary string 110101110010101011010010110101100011010111111 is equivalent to the hexadecimal string 1AE55A5AC6BF.
0001 1010 1110 0101 0101 1010 0101 1010 1100 0110 1011 1111 1 A E 5 5 A 5 A C 6 B F
Notice that we are referring to the zeroes and ones as a string, rather than as a
number; this is not accidental. A group of zeroes and ones (or their equivalent
representation in a another system like hexadecimal) have no value
associated unless we decide to assign a value to them. The zeroes and ones could
represent integers, real numbers, characters, images, sounds, addresses for
memory locations in the computer or even instructions to the computer. The
meaning of the string is unknown without a context. Below we begin to examine
some of the meanings which might be associated with these strings.
The ASCII character code is a somewhat arbitrary system which places each typed character on the computer's keyboard into a 7 (or 8) bit sequence. For example, consider the bits:
01000001_{2} = 41_{16}
What character does this represent? It turns out that inspection of an ASCII table shows us that this is the uppercase "A"
character. Why isn't it the lowercase "t" character? Well, simply, because it
isn't. Someone had to agree on a code and put it into service. This is that
standard code. There are some sensible qualities to the code. For example,
while it's not clear why "A" should be code 41_{16}, it makes sense that
code 42_{16} is "B" and that code 43_{16} is "C", etc.
Not all standard systems are organized that way. For example the EBCDIC system once used by IBM has gaps between the
letters I and J and between R and S. Go figure.
High order bit is leftmost, low order (least significant) bit is rightmost. The location of each bit determines its value:
33222222222211111111110000000000 10987654321098765432109876543210 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB    2^{31} place 2^{10} 2^{0}
EXAMPLE
What is the 32bit unsigned binary integer representation for the decimal integer
86420?
SOLUTION
1. Succesively divide by 2 until the result is zero. The remainders of these divisions will be the bits used to construct the solution.
86420 ÷ 2 = 43210 rem 0 Low order bit 43210 ÷ 2 = 21605 rem 0 21605 ÷ 2 = 10802 rem 1 10802 ÷ 2 = 5401 rem 0 5401 ÷ 2 = 2700 rem 1 2700 ÷ 2 = 1350 rem 0 1350 ÷ 2 = 675 rem 0 675 ÷ 2 = 337 rem 1 337 ÷ 2 = 168 rem 1 168 ÷ 2 = 84 rem 0 84 ÷ 2 = 42 rem 0 42 ÷ 2 = 21 rem 0 21 ÷ 2 = 10 rem 1 10 ÷ 2 = 5 rem 0 5 ÷ 2 = 2 rem 1 2 ÷ 2 = 1 rem 0 1 ÷ 2 = 0 rem 1 High order bit
2. Organize the remainder bits into the binary integer:
101010001100101003. Pad the bits to the left with zeroes to bring to a total of 32:
000000000000000 101010001100101004. Convert to hex:
0000 0000 0000 0001 0101 0001 1001 010000015194
33222222222211111111110000000000
10987654321098765432109876543210
SBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
where
S = 1 for negative number, 0 for nonnegativeThe remaining bits in position n represents 2^{n} place.
What is the 32bit signmagnitude binary integer representation for the decimal integer 47?
SOLUTION
1. S = 1, for negative number.
2. Solve as for an unsigned integer for the remaining 31 bits.
47_{10} = 101111_{2}3. Organize the bits, padding with zeroes between the sign and the magnitude:
1 0000000000000000000000000 101111
1000 0000 0000 0000 0000 0000 0010 11118000002F
00000000
76543210
BBBBBBBB
where the representation is actually the value to be encoded plus some offset
value, which depends on the final (fixed) length of the result. For example, for
an 8bit offset integer, the representation is done as follows.
Begin with the number to be encoded.The examples, below, show how this technique would be used to represent 127, 85, 0, +42 and +127 in 8bit offset:
Add 127 to the number to be encoded.
Note: 127 is chosen because it is 2^{n1}1 where n is the numberThe representation is now encoded as an 8bit unsigned integer.
of bits in the final representation
Both signmagnitude and offset representations have a significant limitation. They cannot be used reliably for mathematical manipulation. Consider, for example, the 8bit signmagnitude representations for +1 and 1. Clearly these two values should add up to zero, but they do not:value value to after be encoded offset encoding 127 + 127 = 0 = 00000000 85 + 127 = 42 = 00101010 0 + 127 = 127 = 01111111 +42 + 127 = 169 = 10101001 +128 + 127 = 255 = 11111111
According to this, +1 plus 1 equals 2. Wrong! Note that binary math works just like decimal math, but with fewer digits. In other words, all we need to remember is 0+0=0, 0+1=1, and 1+1=0, carry the 1.00000001 = +1 in signmagnitude + 10000001 = 1  10000010 = 2
Likewise, offset representations won't work:
Again, we get silly answers: +1 plus 1 equals +127. A system of signed binary numbers must allow us to do binary math correctly. The following representation fits that requirement.10000000 = +1 in 127offset + 01111110 = 1  11111110 = +127
33222222222211111111110000000000
10987654321098765432109876543210
SBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
S = 0 for nonnegative numbers
Interpretation:
the remaining 31 bits represent the magnitude of the nonnegative number.
S = 1 for negative numbers
Interpretation:
Invert all the bits 2'scomplement number.
Add 1.
The resulting 32 bits represent the magnitude of the negative number.
Note: this is the same as subtracting 1 from the 2'scomplement number and then inverting the bits. Click here for more background.
EXAMPLE 1
What is the 32bit 2'scomplement signed binary integer representation for the decimal integer 47?
SOLUTION
1. Solve as for an unsigned integer for the magnitude:
47_{10} = 101111_{2}2. Pad with zeroes to form a 32bit number:
00000000000000000000000000 1011113. If the value was nonnegative, the answer is now complete.
4. For a negative number we must next invert all the bits:
111111111111111111111111110100005. Add one to the result:
111111111111111111111111110100016. Convert to hex:
1111 1111 1111 1111 1111 1111 1101 0001FFFFFFD1
EXAMPLE 2
What is the value of the 2'scomplement number represented by the hexadecimal number FFFFFF99?
SOLUTION
1. Write out the bits:
1111 1111 1111 1111 1111 1111 1001 10012. Since the first bit is a 1 this is a negative number. We must continue. Invert all the bits.
0000 0000 0000 0000 0000 0000 0110 01103. Add 1.
0000 0000 0000 0000 0000 0000 0110 01114. Convert this result to decimal:
1100111_{2} = 103_{10}5. Since the value is negative, the original binary number was the 2'scomplement representation of the decimal number 103.
BINARY ADDITION OF 2'SCOMPLEMENT NUMBERS
Binary addition of a 2'scomplement signed integer is very simple. The rules are
the same as
decimal addition, except that the carry of 1 happens when 1 is added to 1. That
is:
0 + 0 = 0
1 + 0 = 1
0 + 1 = 1
1 + 1 = 0, carry the 1
A carry from the most significant bit position is discarded. The carry out from
the most significant
bit must be the same as the carry in to that bit (either both 0 or both 1),
otherwise an overflow or
underflow error has occurred.
0 0 1 1 note: 0011_{2} = 3_{10}
+ 0 0 1 1 = 3

0 1 1 0 = 6; carry in = carry out of sign bit = 0
1 0 0 1 = 7
+ 0 0 1 1 = 3

1 1 0 0 = 4; carry in = carry out = 0
1 0 0 1 = 7
+ 1 0 0 1 = 7

0 0 1 0 = ERROR; 1 = carry out bit; 0 = carry in to sign
bit
0 1 1 1 = 7
+ 0 1 1 1 = 7

1 1 1 0 = ERROR, 0 = carry out; 1 = carry in
1 1 0 1 = 3
+ 1 1 0 1 = 3

1 0 1 0 = 6; carry out = carry in = 1; carry out bit is
discarded.
1 1 0 1 = 3
+ 0 0 1 1 = 3

0 0 0 0 = 0; carry out = carry in = 1; carry out bit is
discarded.
where33222222222211111111110000000000
10987654321098765432109876543210
SEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFF
= (1)^{s}2^{e127}1.f
s = SDenormals: e = 0; Specials: (NaN, Inf, Inf) e = 255
e = EEEEEEEE, e > 0, e < 255
f = FFFFFFFFFFFFFFFFFFFFFFF
EXAMPLE 1
What is the IEEE 32bit floating point representation for the decimal number 11.5?
SOLUTION
1. Convert to binary. To the left of the binary point, represent the magnitude of the number to the left of the decimal point. To the right of the binary point, represent the fraction to the right of the decimal point (note: this may require a loss of accuracy). The first position after the binary point is the 2^{1} position (0.5 decimal), then 2^{2} (0.25), 2^{3} (0.125), etc.
11.5_{10} = 1011.1_{2}2. Convert to normalized binary scientific notation (i.e. move binary point to the left or right as far necessary until a single one is to left of the binary point, e.g. 1.f):
1011.1_{2} = 1.0111 x 2^{3}Note: in the special case of 0.0, all 32 bits are 0. This is a denormal since there is no 1 to the left of the binary point.
3. Determine s, e and f:
s = 1 for negative, 0 for positive.4. Assemble the 32 bits, padding f to the right with zeroes:
true exponent = 3_{10} = e  127, thus
e = 3 + 127 = 130_{10} = 10000010_{2}
1.f = 1.0111, thus f = 0111
s e+127 1.fffffffffffffffffffffff
1 10000010
01110000000000000000000
11000001001110000000000000000000
5. Convert to hex:
1100 0001 0011 1000 0000 0000 0000 0000
C1380000
Note special cases:
s = 0, e=255, f = all zeroes: +Infinity
s = 1, e=255, f = all zeroes: Infinity
s = 0 or 1, e=255, f = anything but all zeroes: Not A Number
EXAMPLE 2
The previous example was a little simplistic because the fractional portion of the number was a sum of powers of 1/2. This means that the binary representation will be an exact representation of the decimal value. Often, though, this is not possible. Consider, for example, the decimal value 42.42 expressed in IEEE Float.
1. Convert to binary:
First convert the integer portion to an unsigned binary integer:
42_{10} = 101010_{2}
Next convert the fractional portion. This involves a technique which is the
inverse of that for the integer portion. Begin with the value to be represented:
0.42
then successively multiply by 2. The integer portion of each result is used to
create the binary fraction, the fractional portion of each result is used in the
next step. Repeat until the result is 0 or the number of bits allowed is
exceeded. Example:
Assembling the bits we have:0.42 x 2 = 0.84 0.84 x 2 = 1.68 0.68 x 2 = 1.36 0.36 x 2 = 0.72 0.72 x 2 = 1.44 0.44 x 2 = 0.88 0.88 x 2 = 1.76 0.76 x 2 = 1.52 0.52 x 2 = 1.04 0.04 x 2 = 0.08 0.08 x 2 = 0.16 0.16 x 2 = 0.32 0.32 x 2 = 0.64 0.64 x 2 = 1.28 0.28 x 2 = 0.56 0.56 x 2 = 1.12 0.12 x 2 = 0.24 0.24 x 2 = 0.48 0.48 x 2 = 0.96 0.96 x 2 = 1.92 0.92 x 2 = 1.84 < repeats here 0.84 x 2 = 1.68 0.68 x 2 = 1.36
0.42_{10} = 0.01101011100001010001111
Note that the first few 1's are most significant:
0.25 + 0.125 + 0.03125 + 0.0078125 = 0.414065
Now we have:
42.4210 = 101010.01101011100001010001111_{2}
2. Convert to normalized binary scientific notation:
1.0101001101011100001010001111_{2} x 2^{5}
3. Determine s, e and f:
4. Assemble the 32 bits:s = 0 e = 5 e+127 = 5 + 127 = 132 = 10000100_{2} f = 01010011010111000010100_{2} (note that some bits are dropped off the right)
5. Convert to hex:s e+127 1.fffffffffffffffffffffff 0 10000100 01010011010111000010100 01000010001010011010111000010100
0100 0010 0010 1001 1010 1110 0001 0100 4229AE14