# Representing Data

### The information below is provided to help you review and practice converting numbers.

Binary

numbers are expressed in a positional notation system. Each digit represents a power of 2. In an 8-bit pattern the column positions have these values:

27     26    25     24    23    22   21   20

128    64    32    16     8     4     2     1

• For example, the number 11111111 expresses the highest magnitude an 8-bit pattern can represent (128+64+32+16+8+4+2+1 = 255) which is exactly 1 less than the digit value of the next column which is 256

• the radix point  .  separates integers from fractions
• fraction digits mirror the values of the integers:
.1/2  1/4  1/8  1/16  1/32  1/64  1/128  ...

1011.1100 converts to 8 + 0 + 2 + 1 + 1/2 + 1/4 + 0 + 0    =   11 3/4

is a short hand for representing a 4 bit pattern using only a single character (a base 16 digit.)

Excess Notation

makes it possible to store negative values by treating the Most Significant Bit (MSB) as the sign. In excess notation a 0 as the MSB indicates a negative (-) number.

• In the case of the 4 bit pattern, for example:
0110
the value of the most significant bit is 8, so 4 bit patterns are called excess 8.
• To convert this example find the decimal value of the pattern (which is 6);
and subtract 8 (which is the normal value of the MSB).
The result is -2

Two's Complement Notation

is another fixed length approach to representing negative values. It employs a sign bit of 0 to represent non-negative (+) and 1 for negative (-).

• If the number is a non-negative, it may be evaluated as in standard binary notation.
• If the number is negative, evaluating the number involves finding the 1's complement, adding 1 to the result, and remembering the sign.
• Alternatively, the following rule may be applied to find its positive complement.
"Copy the number from right to left up to and including the first "1", then complement the rest of the number.
Evaluate as in standard binary and remember the sign."

Mapping Notation Systems onto Each Other

 Binary Decimal Hexadecimal Excess (8) Two's Complement 0000 0 0 -8 0 0001 1 1 -7 1 0010 2 2 -6 2 0011 3 3 -5 3 0100 4 4 -4 4 0101 5 5 -3 5 0110 6 6 -2 6 0111 7 7 -1 7 1000 8 8 0 -8 1001 9 9 1 -7 1010 10 A 2 -6 1011 11 B 3 -5 1100 12 C 4 -4 1101 13 D 5 -3 1110 14 E 6 -2 1111 15 F 7 -1

Floating Point Notation

consists of 3 parts:

1. a Sign bit ["0" is non-negative  (+), "1" is negative (-)],
2. an Exponent
3. and a Mantissa.
In an eight bit pattern,
• the most significant bit (MSB) is the sign bit,
• followed by a 3-bit exponent (expressed in excess notation),
• followed by a 4-bit mantissa.
• The radix point is assumed to be at the left of the mantissa.
• In a normalized floating point notation, the mantissa must begin with a "1".

E.G. -  0 101 1001

• the sign bit is 0 - so the number represented is non-negative
• the exponent is 101 - which, in excess(4) notation, is 5-4, or +1
• the mantissa is 1001 - the radix goes at the left, producing .1001
• a positive exponent moves the radix to the right and a negative exponent moves the radix to the left.
• applying the exponent shifts the radix 1 position right - 1.001
• which is a 1 and 1/8th.
• Therefore the number 01011001 in normalized floating point notation represents the value +1 1/8th

Here are some more examples for you to try out:

 Number Decimal Hexadecimal Excess(128) Two's Complement Floating Point (normalized) 11101110 238 EE +110 -18 -3 1/2 01011011 91 5B -37 +91 +1 3/8 10111000 184 B8 +56 -72 -1/4

There are only 4 rules for binary addition:

0    0    1    1

+ 0  + 1  + 0  + 1

---  ---  ---  ---

0    1    1   10 (the carry rule)

Subtracting binary numbers

The two's complement notation system is typically used to perform subtraction by using the rules of addition,
e.g., 5 - 4 may be expressed as 5 + (-4)

5 converts to 0101

4 converts to 0100, so -4 must be 1100

0101

+1100

10001

But since we are limited to a fixed length (4 bits in this case) the last carry bit is discarded. This leaves an answer of

0001

Multiplying binary numbers

Multiplication can be re-expressed as repeated addition:

7 * 3 is the same as 7 + 7 + 7
("seven times three" means "add seven together three times")

7 is represented as 0111

0111

+0111

1110

+0111

10101

which is, of course, 21.

Optimising Multiplication

Multiplying large numbers, say 1043 * 131, involves a lot of additions.

For improved efficiency a processor can apply 2 rules:

1. to multiply by a binary number by 2, shift the bits to the left

The decimal number 6 is represented by the binary pattern 110.
Shifting the bits left one position doubles the value of the column of each bit.
So the pattern for decimal 12 is 1100.
Multiplying by powers of 2, then, is simply a matter of shifting the bits left by the exponent.
8 is 23 so multiplying a number by 8 consists of shifting the bits 3 positions left.

In this calculation, 131 is the sum of 128, 2, and 1, so applying the property of Distribution produces an equivalent expression :

1043 * (128 + 2 + 1)
or
1043 * 128 + 1043 * 2 + 1043 * 1

 1043 in binary is 10000010011 1043 * 2 is 100000100110 1043 * 128 is 100000100110000000 Adding these three numbers produces the answer 100001010110111001

Dividing binary numbers

Division can be re-expressed as repeated subtraction:

To divide 21 by 7 see how many times you can subtract 7 from 21.

Of course, this is the same as adding -7, so we use two's complement notation.

21 is represented as 010101

7 is 000111, so -7 is 111001

0 1 0 1 0 1

+    1 1 1 0 0 1

(1) 0 0 1 1 1 0

+    1 1 1 0 0 1

(10) 0 0 0 1 1 1

+    1 1 1 0 0 1

(11) 0 0 0 0 0 0

Since we're using 6 bit patterns, the extra carry bits would normally be discarded, but notice that they contain the integer part of the answer.

The 6 bits to their right contain the remainder.

So 21 divided by 7 is 3, with 0 remainder.