Originally Posted by
joecar
For example, using 1 byte fixed point binary to represent values from 0.0 to < 1.0:
10000000 -> 0.5
01000000 -> 0.25
00100000 -> 0.125
00010000 -> 0.0625
00001000 -> 0.03125
00000100 -> 0.015625
00000010 -> 0.0078125
00000001 -> 0.00390625
(i.e. each position to the right divides by 2)
So, for example, the following combinations represent these values:
11000000 -> 0.75
10100000 -> 0.625
01100000 -> 0.375
10000001 -> 0.50390625
11111111 -> 0.99609375
00000000 -> 0.0
How is 0.004 represented...?
00000001 -> 0.00390625 is the closest;
error = 0.004 - 0.00390625 = 0.00009375 which is smaller than the smallest value representable;
% error = 100*(0.004 - 0.00390625)/0.004 = 2.3%
How is 0.6 represented...?
The closest we can get to 0.6 without going over it is:
10011001 -> 0.5 + 0.0625 + 0.03125 + 0.00390625 = 0.59765625
error = 0.6 - 0.59765625 = 0.00234375 which is smaller than the smallest value representable;
% error = 100*(0.6 - 0.59765625)/0.6 = 0.39%
So you can see that there are many real number values that cannot be represented exactly.