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
1,144

Here's a custom function that converts decimal to binary.Feel free to use it and let me know if you find a bug when you use it.It is developed and tested in SAP Data Services 4.2


#input => base 10
$L_next_no = $G_Decimal_input ;
$L_bin_add ='';
$L_bin ='';
while ( $L_next_no  >= 1.0)
begin
  $L_bin = $L_next_no % 2;
  $L_bin_add = $L_bin_add||''||nvl($L_bin,0) ;
  $L_next_no = $L_next_no / 2;
end
#Reverse
$L_len = length($L_bin_add );
$L_ret = '';
$L_CNT = 0;
while ($L_CNT < $L_len )
begin
   $L_CNT = $L_CNT + 1;
   $L_ret = substr($L_bin_add , $L_CNT, 1) || $L_ret;
end
return($L_ret);

Variables declared

    


     $L_ret                VARCHAR(255)
     $L_next_no      VARCHAR(255) ;
     $L_bin_add     VARCHAR(255) ;
     $L_bin                VARCHAR(255) ;
     $L_len                INT ;
     $L_Ret               VARCHAR(255) ;  (Output)
     $L_cnt                INT ;
    $G_Decimal_input VARCHAR(255); (Input)

_no = $G_Decimal_

Call


print(cf_convert_decimal_to_binary('2684110470'));
Labels in this area