# Decimal to binary conversion

What you should know:

In the lesson on binary numbers we explained that the rightmost bit of a even number in binary is always 0, while in an odd number it equals 1. Moreover, we said that divisions by two can be performed removing the rightmost bit and shifting all the others to the right by one position.

These properties of binary numbers can be used to convert a decimal number to binary: the rightmost bit can be calculated just checking if the number is even or odd. To discover the other bits we just perform several divisions by two, rounding the result to the lowest value. In this way, we can generate decimal numbers whose binary counterpart contains all the bits of the sequence we have to discover, except the rightmost one. This means that, with every division, the second bit in the sequence becomes the first one can be easily evaluated just checking if the result of the last calculation is even or odd.

For instance, if we have to convert the decimal number 74, we already know that the rightmost bit is 0, because the number is even.

Then we divide 74 by two, which yields 37. The result is odd, meaning that the second bit in the sequence equals 1.

The complete calculation can be performed as shown in the following table.

 Number Condition Right bit Binary 74 even 0 1001010 37 odd 1 100101 18 even 0 10010 9 odd 1 1001 4 even 0 100 2 even 0 10 1 odd 1 1

The result can be written from left to right, taking the bits starting from the bottom of the table.

1001010