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
1// string to binary
2parseInt(num.toString(2));
3
4// binary to string
5parseInt(num.toString(2), 2);
1function bin(num) {
2 var binn = [];
3 var c;
4 while (num != 1) {
5 c = Math.floor(num / 2);
6 binn.unshift(num % 2);
7 num = c;
8
9 }
10 binn.unshift(1)
11 return binn
12}
13//returns list of binary nos. in order
14