05-05-2009 3:24 PM
Anybody knows a FM to convert a decimal number into a binary number?
Thx
05-05-2009 3:37 PM
05-05-2009 3:37 PM
05-05-2009 3:44 PM
Thx, but, I need something more directly.
Like
importing parameter - the decimal number
exporting parameter - the binary number written on a char with 16 positions
05-05-2009 3:52 PM
Use the following codes:
Parameter: P_source type p decimals 2.
data: w_int type i,
w_char type c,
w_result(16) type c.
WHILE P_SOURC GE 1.
W_INT = P_SOURC MOD 2.
P_SOURC = P_SOURC DIV 2.
W_CHAR = W_INT .
CONCATENATE W_CHAR W_RESULT INTO W_RESULT .
ENDWHILE. "WHILE P_SOURC GE 1 .
WRITE 😕 'BINARY EQUIVALENT:',W_RESULT.
Regards,
Gurpreet
05-05-2009 4:04 PM
Hello Gurpreet,
Good code ) I was thinking of the same logic but did not put it into ABAP.
Cheers,
Suhas
05-05-2009 4:02 PM
I don't know it it exists, but I think this should work:
REPORT Z_TEST_MONTORI.
DATA the_number TYPE i VALUE 15.
DATA the_original_number TYPE i.
DATA the_rest TYPE i.
DATA the_bit TYPE string.
DATA the_binary TYPE string.
" before start store original number
the_original_number = the_number.
" simple binary conversion
DO.
" put MOD of division by two in head of binary result
the_rest = the_number MOD 2.
the_number = the_number DIV 2.
" convert to string for concatenating
the_bit = the_rest.
CONCATENATE the_binary the_bit INTO the_binary.
IF the_number EQ 0.
EXIT.
ENDIF.
ENDDO.
WRITE : the_original_number, 'in binary is ', the_binary.
best regards
Gabriele