- 1). Write down the powers of two starting at one (remember two to the power of zero is one). Write at least 8 powers of two (1, 2, 4, 8, 16, 32, 64, 128). Sort your powers of two from biggest to smallest, in a small table.
For example:
128, 64, 32, 16, 8, 4, 2, 1
and our integer will be 119 - 2). Compare your integer with the largest power of two. If the power of two is bigger, repeat this process with the next power of two until you find a power of two smaller than your integer.
In the example:
Integer: 119
Since 119 is smaller than 128, write zero. Compare 119 with 64, since 119 is bigger than 64, stop.
128, 64, 32, 16, 8, 4, 2, 1
0, - 3). Divide your integer by the power of two. Write down your quotient under the power of two on the table, and keep your remainder.
On the example:
128, 64, 32, 16, 8, 4, 2, 1
0, 1,
Reminder : 55 - 4). Repeat steps 2 and 3, until you finish all the powers of two on the table.
On the example:
128, 64, 32, 16, 8, 4, 2, 1
0, 1, 1, 1, 0, 1, 1, 1 - 5). Write down the second row on the table as a single number. This will be your byte representation of your integer.
On the example:
01110111 is the byte representation of 119.
previous post