10/6/04

A student writes, and after I responded that we did this at the review sesssion last night, he wrote back pleading that I do it again. So, pussycat that I am, ...

```     Professor Patt,

I have just been reviewing everything from Ch1
through where we are now and
when I got to the floating point section in the
book, I understand using 32
bits to represent floating point numbers
in binary and the formula used to
convert from binary to decimal but
now I have a question about the reverse.
The example in the book showed how to
convert the decimal number -6(5/8) to
binary which is very simple because
5/8 = .625.  Well, what about say, 1/3?
How would you represent .333, .235, .739, etc?
(Numbers that don't fit nicely with 2-1-, 2-2, etc.)  Thank you!

<< Name withheld to protect ..>> (thought I'd save you the trouble)```

So, let's see what .333 looks like in binary.

First, we know that .333 is less than one, so it will be represented as

`     0. b1 b2 b3 b4 b5 b6 b7 ....`

...out to as many binary places as you desire.

Like the integers we worked through in the book, we start with:

`     .333 =  0. b1 b2 b3 b4 b5 b6 b7 ....`

Multiply both sides by two. This gives us

`     .666 = b1 . b2 b3 b4 b5 b6 b7 ....`

Since .666 < 1, b1 must be 0. And, .666 = 0. b2 b3 b4 b5 b6 b7 ....

Multiply both sides by two. This gives us

`     1.332 = b2 . b3 b4 b5 b6 b7 ....`

Since 1.332 > 1, b2 must be 1. And, .332 = 0. b3 b4 b5 b6 b7 ....

Multiply both sides by two. This gives us

`     0.664 =  b3 . b4 b5 b6 b7 ...`

Since 0.664 < 1, b3 must be 0. And, 0.664 = 0. b4 b5 b6 b7 ...

Multiply both sides by two. This gives us

`     1.328 = b4 . b5 b6 b7 ...`

Since 1.328 > 1, b4 must be 1. etc., etc. etc.

Thus we have so far: .333 = 0.0101 b5 b6 b7 ...

A little checking shows that we have so far 1/4 + 1/16 which is .25 + .0625, that is .3125, which is certainly converging in the direction of .333.

OK?

Good luck on the exam.

Yale Patt