Last active
April 28, 2016 20:27
-
-
Save avoidwork/145a8fe50dfed44ed303d5782c1ae46b to your computer and use it in GitHub Desktop.
Binary to decimal
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
function bin2dec (arg) { | |
let output = 0; | |
arg.split("").reverse().forEach((i, idx) => { | |
let v = Number(i); | |
if (v > 0) { | |
output += idx > 0 ? Math.pow(2, idx) : 1; | |
} | |
}); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment