Converting a decimal number to binary format

Converting a decimal number to binary format involves calculation of power of two in sequential order and subtracting that value from original number, For example, if a decimal number 47 needs to be converted to binary format, then first it is necessary to list powers of two. These will be 64, 32, 16, 8, 4, 2, 1. I use small number therefore I did not use the full 8 bits for a binary number,

First we need to compare power of 2 in the first position with the original number. In our case 64 will be compared with 47. 64 is larger then 47, therefore 0 will be in that place, and we can move to the next position. Next position is 32. 32 can fit into 47, therefore we will put one in that place. Next step is to subtract 32 from 47. Difference of these 2 numbers is going to be 15. We will continue doing this operation until the resulting number is going to be equal to 0. If the resulting number will become 0 before the end of binary sequence, then we can assign 0s to the rest of the positions.

In our example decimal number 47 will be converted to 10111 binary number. 

YouTube video

Comments

Popular posts from this blog

Absolute and relative path in HTML pages

Errors

goto PHP operator