| n | n / 2 | n % 2 |
| 35 | 17 | 1 |
| 17 | 8 | 1 |
| 8 | 4 | 0 |
| 4 | 2 | 0 |
| 2 | 1 | 0 |
| 1 | 0 | 1 |
|
- Put the number you want to
convert in the left column (35 in this example) and put the value of that number divided by 2
(using integer division) in the next column, and the remainder of that
division (result of the "mod" operator) in the right column.
In the example below, we'll start with the number 35.
35/2 is 17, with remainder 1.
- In the next row, copy the middle value (17) into the left, and fill out the
other columns appropriately for this number. 17/2 is 8, with remainder 1.
- Continue this process until the number in the n/2 column is zero.
You could continue, but it will soon be obvious that all further digits
from then on will be zeros.
- The resulting binary value is in the last column, but must be
read from bottom to top. The binary representation of
35 is 100011.
|