Skip to content

Instantly share code, notes, and snippets.

@skvggor
Created January 30, 2012 10:21
Show Gist options
  • Save skvggor/1703730 to your computer and use it in GitHub Desktop.
Save skvggor/1703730 to your computer and use it in GitHub Desktop.
Binary to Decimal
/* Binary to Decimal Converter
by Marcker - marckfree@gmail.com
MIT License - < http://opensource.org/licenses/mit-license.php >
*/
function bin2dec(bin) {
var a, c, d, e, i, j, k;
a = bin.split();
c = [];
d = [];
e = 0;
i = a[0].length-1;
for (j=0; j <= a[0].length-1; j += 1) {
c[j] = a[0][j];
d[j] = Number(c[j]) * Math.pow(2, i -= 1);
}
for (k=0; k <= d.length-1; k += 1) {
e += d[k];
}
return e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment