Application Development and Automation 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: 
Read only

DEC TO BIN

Former Member
0 Likes
1,688

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

Thx

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,319

check this fm

FITP_UTIL_CONVERT_DEC2HEX

5 REPLIES 5
Read only

Former Member
0 Likes
1,320

check this fm

FITP_UTIL_CONVERT_DEC2HEX

Read only

0 Likes
1,319

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

Read only

0 Likes
1,319

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

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,319

Hello Gurpreet,

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

Cheers,

Suhas

Read only

Former Member
0 Likes
1,319

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