Jazyk:

BINARY COUNTER

How to encode a number?

If we want to convert a number from decimal to binary, we do it by dividing the number by two, writing down the remainders and dividing the results over and over again by two.

Let’s look at number 29.

We write the remainders to the result number in the reverse order (from bottom to top).

So we write the number 29 in the binary system as 11101. We can use the following table to convert in the opposite direction, ie from the binary to the decimal system. We write the number 29 in the binary system in the third line so that we align it to the right.

Now take each digit (1 or 0) of our number 11101 and multiply it by the power of two in the table above it. Add up all the results.

1*1 + 0*2 + 1*4 + 1*8 + 1*16 = 1 + 4 + 8 + 16 = 29

This way you can easily convert any number from binary to decimal.

If you are converting a very large number and the table is not enough for you, you can extend it to the left by additional columns with ever-increasing powers of two.