Skip to content

Instantly share code, notes, and snippets.

@mjarpitanand
Created November 21, 2017 09:59
Show Gist options
  • Save mjarpitanand/6976eb12ade7a8060c17a457198d4b19 to your computer and use it in GitHub Desktop.
Save mjarpitanand/6976eb12ade7a8060c17a457198d4b19 to your computer and use it in GitHub Desktop.
function dec2bin(num){
var arr = [] , rem =0 , count = "";
var n = num;
while( n > 0){
rem = Math.floor(n % 2);
arr.push(rem);
n = Math.floor(n /2);
}
//alert(arr);
while(arr.length !==0){
count += arr.pop();
}
return count;
}
alert(dec2bin(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment