Skip navigation

So the 100% guaranteed way to convert every decimal number to binary, and in fact any base to any other base, is as follows:

We’ll take the arbitrary number 39(10). Here is the calculation, I’ll explain it afterward.
39/2 = 19.5 <– Remainder is 0.5
19/2 = 9.5 <– Remainder is 0.5
9/2 = 4.5 <– Remainder is 0.5
4/2 = 2 <– Remainder is 0
2/2 = 1 <– Remainder is 0
1/2 = 0.5 <– Remainder is 0.5

Collecting the remainders (the points after the decimal) from the bottom up, we have .5, 0, 0, .5, .5, .5. Multiply each individual digit by the base (2), and we get 1,0,0,1,1,1 which is the actual number: 100111.

So to review the steps,
Take the original number, divide it by the target base and keep track of the remainder. Keep dividing the integer until there is no integer left to divide, at which point collect the remainders from the bottom up and multiply by the target base to obtain your  number.

This works for octal, hexadecimal and any base. Very sweet.

Posted via web from Apphacker’s learning curve

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: