Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
mageshwaran_subramanian
Active Contributor
0 Kudos

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);

1 Comment
Labels in this area