+ 4
From Number to Binary.
Do any of you know how to transform from number to binary number, and if yes, could you please explain a little bit? I have to learn about it, but I don't understand the examples from the internet.
4 ответов
+ 12
That's simple algorithm :
Get a decimal number to convert to binary say 'dec'
You need to divide that decimal number by 2 i.e base of binary repeatedly. collect remainder of each division and at last you'll read these remainders in reverse order.
Let's assume decimal is 11.
11/2=5 and remainder 1
5/2=2 and remainder 1
2/2=1 and remainder 0
1/2=0 and remainder is 1 ¹
Now all you have to do is read these remainders in reverse bottom to up. (Most significant to least significant bit)
And result is 1011 ie. Binary of 11.
Done. 🍻
¹ if number being divided is smaller than divisor in mod division then remainder is the number being divided itself.
Ex . 1/2 =0 and remainder is 1 itself
+ 10
🇮🇳Omkar🕉 explained it nicely, but If you want to build intuition, like why you divide by 2 (or by 16 for hexadecimal conversion) what remainder has to do with the result then I suggest you to convert decimal number to decimal number system (sounds silly) and to think about it:
984/10 =98 remander is 4
98/10 = 9 remainder is 8
9/10 = 0 remainder is 9
0/10 = 0 remainder is 0
remainder is 4, tells you how many ones you have in your number
remainder is 8, tells you how many tens you have in your number, and so on...
9 8 4
9*10² + 8*10¹ + 4*10^0
You divide by 10 because you want this decimal number to convert to decimal, and 10 is base of decimal (denary) number system. You will also notice that this way your remainder will never be greater than 9.
If you want to convert to any other number system, then divide by the base of that number system (for binary is 2, hex 16, octal 8...).
+ 1
Just divide a decimal number (base 10) by 2 and right the remainder as the unit's place of binary number. And divide the quotent by 2 and right the remainder again as the ten's place of the binary and so forth until the remainder quotent becomes 1 and write it in the greatest place value.