Scientific Calculator
shiwei/bin2dec
By ryan
x = bin2dec(b) interprets the binary string B and returns in X the equivalent decimal number. Note: The first char of b should not be ZERO because of the bug of Scientific Calculator
Tagged:
var bin2dec = function(b){
var bs = string(b);
var i = 0;
var j = len bs - 1;
var dec = 0;
while ( i < len bs ) -> (
dec += ( bs[i] - 48 ) * ( 2^j ); //bs are in ASCII code
i += 1;
j -= 1;
);
dec;
}
1 Comment
The bug you referred to should be fixed in the next version (not the one released today unfortunately).
Sign in to leave a comment