Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

DEC TO BIN

Former Member
0 Kudos

Anybody knows a FM to convert a decimal number into a binary number?

Thx

1 ACCEPTED SOLUTION

former_member205763
Active Contributor
0 Kudos

check this fm

FITP_UTIL_CONVERT_DEC2HEX

5 REPLIES 5

former_member205763
Active Contributor
0 Kudos

check this fm

FITP_UTIL_CONVERT_DEC2HEX

0 Kudos

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

0 Kudos

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

0 Kudos

Hello Gurpreet,

Good code ) I was thinking of the same logic but did not put it into ABAP.

Cheers,

Suhas

Former Member
0 Kudos

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