Monday, July 8, 2013

represent a double in [0,1) as binary

First need to understand what is the binary representation for a double in [0,1). Let's see an analogy.  If the number is an integer such as 123 I would probably make something like this

2 ^ 7  = 128 > 123 too large
123 - 2 ^ 6 = 59 -> set bit 1
59 - 2 ^ 5 = 27 -> set bit 1
27 - 2 ^ 4 = 11 -> set bit 1
11 - 2 ^ 3 = 3 -> set bit 1
3 - 2 ^ 2 < 0 -> set bit 0
3 - 2 ^ 1 = 1 -> set bit 1

1 1 1 1 0 1 1  

No comments:

Post a Comment