We want to be able to convert from our normal base 10 numbers
to base 2 and back again. For the moment we'll just do an example.
If we want to write 101 in base 2, we find the highest power
of 2 which is lower than this. The powers are 1,2,4,8,16,32,64,128,....
So we see that 26 = 64 is going to be 1. We can then add 32 to this
and still be less than 101. If we do this we have 101-64-32=5 left.
So 16 and 8 must have 0 coefficients since if they were 1 we would over shoot
our target. 5 is, in powers of 2, 4+1. This means that 101 is
1*26+1*25+1*22+1*20 = 1100101. |
|
To do a simpler example to see what's going on more, we look at 7.
What is this in terms or powers of 2? Again we have 1,2,4,8,16,32,....
Since 8 is greater then 7, we can only use 1,2 and 4. This means that
7 = 1*22+1*21+1*20 = 111. |
|
We can do this in a systematic manner. Given a number, 75 say, we divide
it by two, with perhaps a remainer. Here this leads to 37 with remainder 1.
We then divide 37, which leads to 18, with remainer 1. We repeat
leading to 9, with remainder 0, 4 with remainder 1, 2 with remainder 0
and 0 with remainder 1.
Now list the remainders in reverse order:1001011, which equals:
1*26+0*25+0*24+1*23+0*22+1*21+1*20 = |
|
1*64+0*32+0*16+1*8+0*4+1*2+1 = 64+8+2+1 = 75. |
|