Skip to main content

Command Palette

Search for a command to run...

The "No-Panic" Guide

binary basics:How to convert decimals without panicking

Updated
5 min read
The "No-Panic" Guide
A
i basically prefer open grounds on topic selection but you can sum it up on networking and cybersecurity world.

So in todays concept of learning out loud we have binary numbers. We call 0 and 1(zero and one) as binary numbers. These are the magic two numbers used to communicate with computers by us humans.

Lets suppose we have the number 10001010. To a human this just looks like a sequence of digits, but in computer networking we often treat it as a binary number. Its sequence or combination of 8 bits in computer world. You must be wondering what is this bits? This bit is exactly those magic two numbers 0 and 1 and 10001010 this is sequence of those numbers.

In technical definition a bit is the smallest unit of data in computing and since this number combination has 8 bits 10001010 it can be called 1 byte. Bingo new conversion 8 bits = 1 byte.

And this binary number has a base that’s 2(two). Why 2? Because binary world has only 2 digits that you can work with 0 and 1. So its base is 2. Why am I saying you that? Because in every calculation you do for binary numbers we use 2 and the reason is quite clear.

(extra knowledge there is another number system called decimal that has base 10 why? It includes 10 digits those are 0 1 2 3 4 5 6 7 8 9. Binary and decimal both include the digit 0 as part of their number system.)

So in networking we work with binary and decimal number system. And remember we needed conversion of binary to decimal and decimal to binary quite often.

Remember how in our middle school teacher used to say when we convert bigger number into smaller we divide and smaller into bigger number we multiply. We imply that here as well. To convert from decimal to binary, we repeatedly divide by the base of the target system, which is 2. Binary is a smaller number system so when we convert it into decimal we multiply with powers of two.

Lets go with division first because its really short and simple.

We have the example number 138(see how every digit is from 0 to 9: 1, 3, 8 that is considered decimal) as a decimal number to convert into binary.

We have to divide it by two and repeatedly divide it until we get 0 or 1 as a quotient. And track remainder in every single step of division.

Bingo we caught the confusion line, I know its getting complicated let me do one simple step we divide 138 by 2 that gives us 0 remainder and 69 as quotient.

We end here why to continue we got 0 as remainder right?

No because the quotient is 69 nowhere near to 0 or 1.

We divide that again with 2.

Oh no 69 is a odd number that will give us decimal quotient.

No worries we will divide 69 as usual with 2 leaving 1 as a remainder.

How?

As 69 is a odd number removing 1 out gives us 68(i.e even number) that gives us a quotient of 34 as remainder 1.

Again the same process.

34/2 = 17 with quotient 17 and remainder 0.

Again 17/2 which is take out the remainder 1 automatically as we have odd number detected.

Now 16/2 = 8 with quotient 8 and remainder already taken out 1.

Again 8/2 = 4 gives 0 remainder quotient 4.

Again 4/2 = 2 gives us quotient 2 and remainder 0.

Finally 2/2 = 1 gives us quotient 1 and remainder 0.

We finally stopped because we got 1 as quotient. Just remember whatever decimal number we got divide it by two repeatedly and everytime the result is divisible the remainder is 0 otherwise its 1.

Now we assemble, how?

We assemble the remainder from back.

Back? Where?

The last remainder we got was 1 so we assemble the remainder from the very end.

2/2 = 1 gives 0 remainder,

4/2 = 2 gives 0 remainder,

8/2 = 4 gives 0 remainder,

17/2 = 8 with 1 remainder,

34/2 = 17 gives 0 remainder,

69/2 = 34 with remainder 1,

138/2 = 69 remainder 0.

We write 0001010.

But we are adding another number to our final answer.

0001010 this is with assembling all remainder from the end of the division right?

We add the ending quotient we got as a sign to end the repeated division as an honour to the starting of our answer.

Remember we got:

2/2 = 1

with 1 quotient and 0 remainder.

Now the ending “1” quotient goes right to the starting of the final answer of assemblance of remainder.

That gives the actual final answer:

10001010

I am saying this at the very end because remember to NOT append any other quotient in your answer only the very end one.

Why? You must wonder.

Binary number is a formation of just 0 and 1 and we stop when the quotient becomes 0 or 1 because there is nothing left to divide meaningfully by 2. That final quotient becomes part of our answer, so DO NOT forget to append the final quotient either its 1 or 0 at the final assemblance of remainder(this assemblance always starts from the end or tail).

We will learn the binary to decimal in another blog!!!