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'));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
7 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 | |
3 |