Skip to content

Instantly share code, notes, and snippets.

@kenduigraha
Created November 14, 2017 05:12
Show Gist options
  • Save kenduigraha/42c4189f1f8e945c3389eac1c09f5050 to your computer and use it in GitHub Desktop.
Save kenduigraha/42c4189f1f8e945c3389eac1c09f5050 to your computer and use it in GitHub Desktop.
decimalToBinary
var result = [];
var count = 0;
var resultCount = [];
function decimalToBinary(decimal) {
var divide = decimal / 2;
var divideRound = Math.floor(divide);
decimal % 2 != 0 ? result.push(1) : result.push(0);
if (divideRound > 0) decimalToBinary(divideRound);
return result.reverse().join('');
}
console.log(decimalToBinary(99))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment