Created
November 14, 2017 05:12
-
-
Save kenduigraha/42c4189f1f8e945c3389eac1c09f5050 to your computer and use it in GitHub Desktop.
decimalToBinary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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