Quantcast
Channel: SCN : Blog List - Data Services and Data Quality
Viewing all articles
Browse latest Browse all 222

Custom function: Decimal to Binary conversion

$
0
0

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

Viewing all articles
Browse latest Browse all 222

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>