Initializing base value to 1 i . e 2 ^ 0
var base = 1 ; var len = num . length ; for ( var i = len - 1 ; i >= 0 ; i -- ) { if ( num . charAt ( i ) == ' ' ) dec_value += base ; base = base * 2 ; } return dec_value ; }