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

 

Binary Fractions (radix point)

    .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


Hexadecimal Notation

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.


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 (-).

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,

E.G. -  0 101 1001

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


Adding binary numbers

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

Add these two together:

 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
  2. multiplicaion Distributes over addition

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.