1function dec2bin(dec){
2 return (dec >>> 0).toString(2);
3}
4
5dec2bin(1); // 1
6dec2bin(-1); // 11111111111111111111111111111111
7dec2bin(256); // 100000000
8dec2bin(-256); // 11111111111111111111111100000000
1const convertNumberToBinary = number => {
2 return (number >>> 0).toString(2);
3}
4
1// Javascript convert a number to a binary equivalent.
2// Syntax: n.toString(radix)
3// Note that radix in this syntax is the radix n will become.
4let n = 100;
5let binary = n.toString(2);
6// => 1100100
7
8// Convert a binary number to a radix of 10 equivalent.
9// Syntax: parseInt(num, radix).
10// Note that radix in this syntax is denoting i's current radix.
11let i = 1100100;
12let number = parseInt(i, 2);
13// => 100