binary converter javascript code example
Example 1: number to binary javascript
const convertNumberToBinary = n => {
let binary = (n >>> 0).toString(2).split('').sort().join('');
let number = parseInt(binary, 2);
return number;
}
Example 2: number to binary javascript
function convertNumberToBinary (num) {
return parseInt([...num.toString(2)].reverse().join(''), 2);
}
function convertNumberToBinary (num) {
return parseInt(num.toString(2).slice('').reverse().join(''), 2);
}
function convertNumberToBinary (num) {
let binary = (n >>> 0).toString(2).split('').sort().join('');
let number = parseInt(binary, 2);
return num;
}