DEV Community

Stefan Dalyan
Stefan Dalyan

Posted on

How to convert decimals into binary numbers

How to convert decimals into binaries? It is an essential tool for any software or hardware engineer to know, so in this post, I'll describe the easiest way to convert for people with no experience. Firstly, lets understand the usage of binary numbers in computer science. Binary numbers are used in computers (CPU, RAM) to accomplish different tasks. I will explain the subtraction method, as mentioned earlier, it is the most practical method for newcomers. To convert, let's pick a random number, let it be 77. Next, we need to find a number with a base of 2, which is bigger than the chosen number, in my case, it is 128. The biggest number with a base of 2, which is smaller than 77, is 64. We found this exact number because we need to subtract it from 77 and not get a negative integer. 77-64 equals 13, and the next step is basically the repetition of the last one, so we find a number smaller than 13 but bigger than other options (it is 8). 13-8=5, and we continue picking the numbers, the nearest number in the list is 4. 5-4 is 1, and eventually, we get to the end by subtracting 12 from 1 and getting 0 as a result. As the subtraction is done, we need to put numbers 0 for the numbers which were not used in the method and 1 for the numbers in the subtraction. 128=0, 64=1, 32=0, 16=0, 8=1, 4=1, 2=0 and 1=1. Hence, we get the number 01001101. Hope it was helpful))).

Top comments (0)