Skip to content

Instantly share code, notes, and snippets.

@avoidwork
Last active April 28, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avoidwork/145a8fe50dfed44ed303d5782c1ae46b to your computer and use it in GitHub Desktop.
Save avoidwork/145a8fe50dfed44ed303d5782c1ae46b to your computer and use it in GitHub Desktop.
Binary to decimal
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