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.5Collecting 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.