Showing posts with label Algorithm. Show all posts
Showing posts with label Algorithm. Show all posts

Thursday, 16 November 2023

Quick num to binary conversion

 credit to my self @Joey

function bin(n) {

let array = [];

while(n) {

array.push(n%2);

n>>=1;

}


return array.reverse().join('')

}




function bin(n) {

let array = [];

let str = '';

while(n) {

array.push(n%2);

n>>=1;

}

while(array.length > 0) {

str += array.pop()

}


return str;

}