You are on page 1of 4

Data Representation Real Numbers

– We have seen how various data (numbers, colours, – Real Numbers are numbers with a fractional part.
positions, letters) can be stored as binary numbers. 102 101 100 10-1 10-2 10-3
– Not all values that need to be stored are whole numbers. 3 1 . 1 4 3
(integers) – Just as 31.143 can be constructed using negative powers of
– Not all values that need to be stored are greater than zero. 10 (10-1 = 1/10+1 = .1), the same is true in binary
(positive) • Example: Convert 11.101 Binary to decimal
– Not all values can fit in 8-bit or 16-bit registers. (small 22 21 20 2-1 2-2 2-3
numbers)
1 1 . 1 0 1
= 2 + 1 + 1/21 +0 + 1/23
– How does the computer store real numbers (fractions) ?
= 3 + .5 + .0125
– How does the computer store negative numbers ?
= 3.512510 = 11.1012
– How does the computer store very large numbers ?

Spring 2001 CA103 Computer Architecture


Ray Walshe
Page 1 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 2

Binary Fractions Binary Fractions


– Example: Convert 101.110012 to Decimal – The Binary Fraction Table
First write down the powers of two (positive and negative). 2-1 = 1/2 = .5
22 21 20 2-1 2-2 2-3 2-4 2-5 2-2 = 1/4 = .25
1 0 1 . 1 1 0 0 1 2-3 = 1/8 = .125
= 4 + 1 + 1/21 + 1/22 + 1/25 2-4 = 1/16 = .0625
= 5 + .5 + .25 + .03125 2-5 = 1/32 = .03125
2-6 = 1/64 = .015625
= 5.7812510 = 101.110012 2-7 = 1/128 = .0078125
– Exercise: 2-8 = 1/256 = .00390625
• Convert 11.1001 to Decimal.
Example: Convert 2.15625 to Binary. (2 =102 ..only need to do fraction.)
• Convert 1.10101 to Decimal. Starting with the largest fraction that can be used (.125) we take that away.
• Convert 111.101101 to Decimal. 0.15625 - 0.125 = .03125 (We record that we used the 2-3 fraction)10.001
0.03125 - .03125 = .0 (We record that we used the 2-5 fraction)10.00101
Answer 10.00101
Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 3 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 4

Binary Fractions Binary Fractions


– Example Convert 9.3437510 to Binary 2-1 =.5 – Problem:- Convert 5.310 from decimal to binary
(A) 9 in Binary is 1001 (8+0+0+1) 2-2 =.25 5.310 = 4 + 1 + 0.25 + 0.03125+ 0.015625 + ........
(B) We need to convert the fraction part. 2-3 =.125 = 2 2 +2 0 +2 -2 +2 -5 +2 -6 ....
2-4 =.0625
.34375 is smaller than 2-1 so put a 0 down 2-5 =.03125 = 1 0 1 . 0 1 0 0 1 1 0 0 1 1 0 01..
.34375 is bigger than 2-2 so put a 1 down 2-6 =.015625
and subtract (.34375 - .25) 2-7 =.0078125 Fractional Numbers which have an exact representation in decimal,
.09375 is smaller than 2-3 so put a 0 down 2-8 =.00390625 may be repeating fractions in binary.
.09375 is bigger than 2-4 so put a 1 down
.34375
and subtract (.09375 - .0625) -.25 The Sum of any combination of the binary fractions will result in a
.03125 is equal to 2-5 so put a 1 down and .09375 decimal fraction that ends in 5.
subtract (.03125 - .03125 = Zero all done) -.0625
This implies that all other decimal fractions (including some that end
23 22 21 20 2 -1 2-2 2-3 2-4 2-5 .03125
-.03125 in 0 or 5 see above) have no exact representation in binary.
1 0 0 1 . 0 1 0 1 1
.00000
Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 5 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 6

1
Binary Fractions Negative Numbers
– Exercise:
• Convert 4.75 to Binary. Positive Integer numbers are represented simply by their binary
equivalents.
• Convert 7.046875 to Binary.
i.e. 3910 = 0 0 1 0 0 1 1 1 = 2716
• Convert 10.4375 to Binary. A problem arises when we come to consider the representation of
negative numbers.
One obvious way would be to use bit 7 as a sign bit.
i.e. -39 =1 0 1 0 0 1 1 1 = A716
In this way one byte could represent numbers from
-127 to +127 (Do you know why ?)
Note that this “sign and magnitude”representation is the same as
that which we use when representing negative numbers in
decimal. On a computer - It is not done like that
Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 7 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 8

Negative Numbers Negative Numbers


– Before looking at how negative numbers are stored we – Back to School - Subtraction.
should address basic binary addition • Subtract 84 from 31.
– Rules: 0 + 0 = 0
31 84
0 + 1 = 1
- 84 + 999947
1 + 0 = 1
..99947 ?? ..000031 Correct !
1 + 1 = 0 PLUS a Carry of 1
1 + 1 + 1= 1 PLUS a Carry of 1
– The reason this works is because we are fixing the limits of
the resulting numbers (something falls off the end which we
– Examples: ignore.. It actually is stored in the carry flag)
0 1 1 3 0 1 0 1. 1 1 5.75 – This is called precision. The result is accurate to a number of
+ 01 1 0 +2 01011101. 01 1 +2.25 fixed places. Can we use this technique in the computer
where the registers/memory are fixed sizes ?
1 0 1 5 1 0 0 0. 0 0 8.00

Spring 2001 CA103 Computer Architecture


Ray Walshe
Page 9 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 10

Negative Binary Numbers Negative Binary Numbers


– Lets try the same technique on sample binary numbers of – Positive and Negative 4-bit Binary Numbers table
fixed 4-bits in length 0000 0 1000 -8
0110 6 0100 4 0001 1 1001 -7
- 0100 4 - 0110 6 0010 2 1010 -6
0010 2 1 1110 -2? 0011 3 1011 -5
0100 4 1100 -4
0100 4 0110 6 0101 5 1101 -3
+ 0010 2 + 1110 -2? 0110 6 1110 -2
0110 6 1 0100 4 0111 7 1111 -1
This representation of negative numbers in binary is called 2’s
Compliment

Spring 2001 CA103 Computer Architecture


Ray Walshe
Page 11 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 12

2
2’s Compliment 2’s Compliment
– In 2’s Compliment all positive numbers begin with a “zero” – Example: Convert the 8-bit number 23 to -23.
and all negative numbers begin with a “one” 0 0 0 1 0 1 1 1 Change all 0’s to 1’s
– One way of getting the negative equivalent of a number is to 1 1 1 0 1 0 0 0 and 1’s to 0’s
subtract it from zero. + 1 THEN Add 1
0 00000000 0 1 1 1 0 1 0 0 1 (-23)

- 3 - 00100111 39
-3 – Example: Convert the 8-bit number 19 to -19
1 11011001 -39
0 0 0 1 0 0 1 1 Change all 0’s to 1’s
– An easier way of converting to/from 2’s Compliment is to 1 1 1 0 1 1 0 0 and 1’s to 0’s
“change all the bits and ADD 1” + 1 THEN Add 1
0 0 1 0 0 1 1 1 1 1 1 0 1 1 0 1 (-23)
1 1 0 1 1 0 0 0 All “1’s” become “0’s”
All “0’s” become “1’s”
+ 1
THEN Add “1”
1 1 0 1 1 0 0 1
Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 13 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 14

2’s Compliment Exercises


– Example: Add the 8-bit numbers 19 + (-23) – Convert the following numbers to their 8-bit binary
0 0 0 1 0 0 1 1 8-bit binary 19 equivalents.
+ 1 1 1 0 1 0 0 1 8-bit binary(-23) • 17 11 22 19 13 15
1 1 1 1 1 1 0 0 (Answer ?? -4 ??)
• -17 -11 -22 -19 -13 -15
The answer is a minus number (Most Significant Bit is 1) so – Show how a computer would perform the following 8 bit
convert it to a positive number binary calculations
1 1 1 1 1 1 0 0 (Answer ??)
• 17 - 11 (Remember it’s [ 17 + (-11) ] )
0 0 0 0 0 0 1 1 Invert all the digits
+ 1 THEN Add One
• 11 - 17
0 0 0 0 0 1 0 0 Answer 4 (Don’t forget • 22 - 19
the sign is minus) • 13 - 15
19 + (-23) = -4. The computer has no subtraction circuitry so
this is really how it works. When it needs to perform A - B it
converts +B to -B and then ADDS A + (-B).
Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 15 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 16

Multi-Byte Numbers Floating Point Numbers


Largest positive number in 8-bit location (127) 0 1 1 1 1 1 1 1 – Larger numbers than this can be stored using floating pint
representation.
Largest negative number in 8-bit location (-128) 1 0 0 0 0 0 0 0 – Any Real Number can be divided into two parts
The Mantissa and the Exponent
Q. Using 2’s compliment the range of numbers in 8-bits is -128 to +127 but
using sign and magnitude it’s -127 to +127. Why ? 2
27.325 = .27325 x 10
Q. How can we store larger numbers ? -3
A. Use more bytes. .000762 =.762 x 10
151413121110 9 8
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
7
1,000,000 = .1 x 10
0 1 1 1 1 0 0 1 1 0 1 0 1 0 0 0
Most Significant Byte Least Significant Byte

Using two bytes, numbers can be stored in the range -32,768 to +32,767

Spring 2001 CA103 Computer Architecture


Ray Walshe
Page 17 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 18

3
Floating Point Binary Numbers Floating Point Binary Numbers
– In binary we can use 8 bits for the mantissa and 8 bits for
the exponent. Largest Positive floating point number using previous example.
1112 = .11100000 x 200000011 .1111…111111 x 2 01111111111
=-3
.0001112 = .11100000 x 211111101 Smallest Positive float.point number using previous example.
OR .0001112= .01110000 x 211111100 =-2 .1000…000000 x 2 10000000000
To avoid possible redundancy - many representations of the same number are 52 bit mantissa 11 bit exponent
possible -the mantissa is Normalised. That is the mantissa is shifted right Q. How is zero represented ?
and the exponent decremented until the Most Significant bit of the Mantissa
is a 1.
The mantissa is stored in Sign & Magnitude form, and the exponent in 2’s Exercise: Show how the following numbers would be represented using
complement form. floating point binary with 8-bit mantissa and 8 bit exponent.
A typical implementation might actually use 11 bits for the exponent, 52 for the (a) 1110110 (b) 1011 (c) 00101101
mantissa, and 1 bit for the sign of the mantissa - a total of 8 bytes (d) .001001 (e) .000011 (f) .010101
The largest positive number that can be represented in this format is:

Spring 2001 CA103 Computer Architecture


Ray Walshe
Page 19 Spring 2001 CA103 Computer Architecture
Ray Walshe
Page 20

You might also like