Professional Documents
Culture Documents
– 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 ?
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
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
Using two bytes, numbers can be stored in the range -32,768 to +32,767
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: