Binary to decimal conversion
Here’s a piece of code which takes the binary number as input and convert them into a decimal output
$l_input is varchar and rest of the variables are of type int.
#$l_input = '100111101111'; (=2543)
$l_len = length($l_input);
$l_lastDigit = 0;
$l_sum = 0;
$l_i =0;
while ( $l_i < $l_len)
begin
$l_lastDigit =substr($l_input,length($l_input),1) ;
$l_sum = $l_sum + $l_lastDigit * power(2,$l_i);
$l_input = substr($l_input,1,length($l_input)-1 ) ;
$l_i = $l_i + 1;
end
print ($l_sum);
Hi, Give me more information on issue