Created
January 30, 2012 10:21
-
-
Save skvggor/1703730 to your computer and use it in GitHub Desktop.
Binary to Decimal
This file contains hidden or 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
/* Binary to Decimal Converter | |
by Marcker - [email protected] | |
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