I am currently reading Charles Petzold's book 'Code'. In it he explains how to convert a decimal number into binary using the following template:
[ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]
÷128 ÷64 ÷32 ÷16 ÷8 ÷4 ÷2 ÷1
[ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]
In the book, his explanation on how to use the template reads:
"Put the entire decimal number (less than or equal to 255) in the box in the upper left corner. Divide that number (the dividend) by the first divisor (128), as indicated. Put the quotient in the box below (the box at the lower left corner), and the remainder in the box to the right (the second box on the top row). That first remainder is the dividend for the next calculation, which uses a divisor of 64. Continue in the same manner through the template.
Keep in mind that each quotient will be either 0 or 1. If the dividend is less than the divisor the quotient is 0 and the remainder is simply the dividend. if the dividend is greater than or equal to the divisor, the quotient is 1 and the remainder is the divider - the divisor. Here's how it's done with 150:"
[150] [22] [22] [22] [6 ] [6 ] [2 ] [0 ]
÷128 ÷64 ÷32 ÷16 ÷8 ÷4 ÷2 ÷1
[1 ] [0 ] [0 ] [1 ] [0 ] [1 ] [1 ] [0 ]
But I'm puzzled! When I do the calculations as instructed, I'm getting very different results. What I'm doing is as follows:
150 ÷ 128 = 1.171875 (I don't see where the 22 comes from above?) So, I place a 1 in the box below the 150 and then carry the 171875 and use that as the dividend for the next calculation, which of course gets me into all sorts of problems, and ultimately, not the binary number 10010110!
Can somebody tell me where I'm going wrong?