Skip to main content

Posts

Showing posts from August, 2017

JavaScript: How to Convert One Number Base (Radix) to Another

Decimal to Binary For instance, we have a number, 7 , which is a base-10 number. And we need to convert it to base-2 (binary) number. The base-2 system uses the addition of power of 2s to get the number we have in another radix system. So, in this case, we continuously divide that base-10 number by 2 . And then we take the remainder of each division as the base-2 number. In paper and pen scribbling, we do this: 7 ÷ 2 ➡️ closest multiplier is 3, remainder 1 3 ÷ 2 ➡️ closest multiplier is 1, remainder 1 1 ÷ 2 ➡️ the only multiplier is 0, remainder 1 ⬆️ Put all remainders as a number . ⬇️ Take each from the bottom : 1 ➡️ 1 ➡️ 1 . Meaning, 7 in binary system is 111. $7_10 = 111_2$ Or, we could use the addition method of power of 2: $$ 7 = (\bo1 × 2^2) + (\bo1 × 2^1) + (\bo1 × 2^0)$$ Look at the multiplier (1), read it from the left : 1 ➡️ 1 ➡️ 1 . Similar to prior method, 7 in base-10 is equal to 111 in base-2 system. $7_10 = 111_2$ Ja...
Monkey Raptor uses biscuits. More info on Privacy Policy