DEV Community


Today I learned a small trick on how to count in Binary

Hey 🖐, I am a 16 years old developer and I'm located in Germany. Javascript enthusiast. I hope you enjoy my content. If you want to see my work ↘️
・2 min read

Hey welcome back,

Today I learned a small trick on how to count in binary. It is really simple.

How to do it? You need to divide it by two until you reach the number 1, but you need to ignore the numbers after the comma, and important is that you don't round the number you get after you divide it by 2. We will try now to get the binary number of the number 45.

45/2 22/2 11/2 5/2 2/2
45 22 11 5 2 1

Now we have divided everything by two and got the last number the last part is to add under every even number a 0 and under every odd number a 1 then our table will look like this:

45/2 22/2 11/2 5/2 2/2
45 22 11 5 2 1
1 0 1 1 0 1

Now it looks like this and we got the binary number 101101 in this example it is not necessary to flip the binary number (101101) but I had to flip the binary number because sometimes I got another number then I needed. Here is another example for the number 34 where you need to flip the binary number at the end:

34/2 17/2 8/2 4/2 2/2
34 17 8 4 2 1
0 1 0 0 0 1

Then we get the binary number 010001 but this number is the wrong number we need to flip it then our binary number looks like this: 100010 now if we check it with a Decimal to Binary online converter we can see that we are right here is the prove:

Here is the prove

To the Converter

I hope you enjoyed this blog post. If you have any idea or recommendation feel free to write a comment :)

Discussion (1)

braydentw profile image
Forem Open with the Forem app