algorithm - Converting a decimal number into binary -


I am currently reading Charles Petzold's book 'Code'. Here's how to convert the decimal number to binary using the following templates:

<> [] [] ÷ 128 ÷ 64 ÷ 32 ÷ 16 ÷ 8 ÷ 4 2 ÷ 1 [] [] [] [] [] [] [] [] [] [] [] [] [/ code>

In this book, his explanation about the use of templates Read:

"Keep the entire decimal number (less than or equal to 255) in the box in the upper left corner, first divide that number (dividend) by the separator (128), as Has been indicated Enter the quotient (box located in the lower left corner) in the box below, and the rest of the box to the right (the second box on the top row). This first balance is the dividend for the next calculation, which uses a divisor of 64. The template Keep in the same way through the medium.

Keep in mind that each quotient will be 0 or 1. If the dividend is less than the separator, the quotient is 0 and the derivative is only dividend if the dividend is The equalizer is equal to or equal to The quotient is 1 and the remainder is the partition - how is it done with the distributor 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 when I calculate according to the instructions, I am getting very different results. Here's what I'm doing:

150 ÷ ​​128 = 1.171875 (What do I do above '22? ') So, I'm down to 150 I put one 1 in the box and then 171875 and use it as a dividend for the next calculation, which definitely gives me all kinds of problems, and finally, The binary number is not 10010110!

Can anyone tell me where I am going?

22 left of 150/128.

Since you have determined that 1 in 128 "in" is 150, and one value is given for that bit, you can forget about 128 in "in" 150, Take away from 150, leave our 22. Then for the 64: 64 issue, this time is not in 22, so the digit is 0. And likewise worth 32 for points. Then goes to 22 points once for the 16 digit, then there is 1 point, and now you are working with 16 "in" 22, so take it away - except 6. And so on.

(Consider the same base 10 case, let's say 309. Take the column of 100; There are 3 100s in 309, so you put 3 there and now 9 are left then 10 Take the S column; 9 is 10s, so you put 0 there, and then 1 s column: 9 in 19, so you put 9 there. And now nothing is left - you have done .)

I feel a terrible feeling, it can be more confusing than to clarify, but in the same way what about it Octa am.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -