Thursday, September 03, 2009 1:50 AM,
The second thing I wanted to provide was an example for you to go over before you tackle the new problem 8 on the first problem set is a mechanism for taking a decimal fraction and putting it into normalized form. In problem 8, I am asking you to do this for the value 0.3. Here I will show you how to do it for the value 0.09. I will use a method very similar to the method I showed you for dealing with integers in class. Let's say I wanted to form the first six significant binary digits of 0.09. That is, 0.09 is approximately equal to 0. b(-1) b(-2) b(-3) b(-4) b(-5) b(-6). I say, approximately equal becauase the actual binary string is infinite. You know, I hope, that 0.1111111111111111 is less than 1. That is, 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + ... is always less than 1. You probably saw the proof of that expressed as: Start on one side of the room, and walk half way to the other side (1/2). Now walk half of the remaining half (1/4). Now half of the remaining half (1/8). Keep doing this. You can never reach the other side! It should be also clear that 0.011111111111 is always less than 1/2. Now we are ready. We start with: 0.09 = b(-1)*2^(-1) + b(-2)*2^(-2) + b(-3)*2^(-3) + b(-4)*2^(-4) + b(-5)*2^(-5) + b(-6)*2^(-6) Note that 0.09 is less than 1/2. So, b(-1) must be 0. Now remove the b(-1) term, multiply 0.09 by 2, and all terms on the right by 2, giving us 0.18 = b(-2)*2^(-1) + b(-3)*2^(-2) + b(-4)*2^(-3) + b(-5)*2^(-4) + b(-6)*2^(-5) Note that 0.18 is less than 1/2. So b(-2) must be 0. Remove the b(-2) term, and multiply everything by 2, yielding: 0.36 = b(-3)*2^(-1) + b(-4)*2^(-2) + b(-5)*2^(-3) + b(-6)*2^(-4) And, b(-3) = 0. The same operation yields: 0.72 = b(-4)*2^(-1) + b(-5)*2^(-2) + b(-6)*2^(-3) 0.72 is larger than 1/2, so b(-4) must be 1. Subtract .5 from .72, and removing b(-4) gives us: 0.22 = b(-5)*2^(-2) + b(-6)*2^(-3) Multiplying by 2 gives us 0.44 = b(-5)*2^(-1) + b(-6)*2^(-2) Since .44 is less than 1/2, b(-5) =0. Repeating the operation gives us: 0.88 = b(-6)*2^(-1) Since .88 is greater than 1/2, b(-6) = 1. We still have .38 to deal with (once we subtract the .5 due to b(-6). That will be the contribution due to b(-7), b(-8), b(-9), which thankfully we don't have to laboriously go through since I am allowing us to stop here. The result is obtained by pulling together all that we have done: That is, 0.09 is approximately equal to 0.000101. If you want to check it, try adding 1/16 + 1/64. What do you get? The difference between what you get and 0.09 is due to the fact that we stopped at b(-6). Try a few more digits, and note that you keep getting closer to 0.09 (never going above 0.09)! Finally, as an exercise, let's put this number in normalized form: We move the binary point 4 places to the right and divide by 2^4. The result: 1.01 * 2^(-4) And for one last bit of practice, if I wanted to represent that as a 32-bit floating point number: 0 01111011 01000000000000000000000 And, I am done. Good luck! Yale Patt