2013 Oct 13 7:15 PM
Hi
How to convert Binary number to hex.
Ex : Binary number = 1000
Hexa Number = 8
Example 2 :
Binary number = 10001010
Hexa Number = 8A
Please help me to solve this issue.
Moderator message: Sorry no spoon-feeding. Points awarded removed.
Message was edited by: Suhas Saha
2013 Oct 13 7:43 PM
Hello Nagesh,
try these..
Decimal to binary.
Parameter: Decimal type p decimals 2.
data: int type i,
char type c,
result(16) type c.
WHILE Decimal GE 1.
INT = Decimal MOD 2.
Decimal = Decimal DIV 2.
CHAR = INT.
CONCATENATE CHAR RESULT INTO RESULT .
ENDWHILE. "WHILE Decimal GE 1 .
WRITE 😕 'BINARY = :',RESULT.
Same Logic you can use for Hexa decimal also.
INT = Decimal MOD 16.
Decimal = Decimal DIV 16.
Case int
When 10.
char = 'A'.
When 11
char = 'B'..
...
Rest of code you can do by yourself.
Hexa to deci....
DATA deci TYPE i.
DATA hexa TYPE X.
hexa = '10'.
deci = hexa.
" CRM_EI_KB_CONV_DEC_TO_HEX "
This fm converts any decimal to hexadecimal,
For more info. Please Search on Google how to convert Decimal to binary and Hexa and then try to modify my code
2013 Oct 13 7:53 PM
HI Chandra Shekhar , I want to convert Binary number to Hexa number , Your code is not helping me.
Please have a look on the screen snap.
2013 Oct 13 10:40 PM
Hi,
What is the type of the variable where you have the Binary Number in. Is it Character field then you can use OFFSET and CASE statement and get to the HEX equivalent. Or else You can use the SET BIT and GET BIT key words to get the desired results. Check the link below
http://help.sap.com/saphelp_nw04/helpdata/en/b6/e7d716f46711d195200000e8353423/frameset.htm
Cheers,
Arindam
2013 Oct 14 5:02 AM
Arindam
Can you provide me with an example by considering the above chart plz.
2013 Oct 14 7:03 AM
Enjoy
DATA lv_input TYPE string VALUE '101011'.
DATA: lv_digit TYPE i,
lv_remain TYPE i,
lv_loop TYPE i VALUE 0,
lv_length TYPE i,
lv_char TYPE string,
lv_output TYPE i,
lv_result TYPE string.
lv_length = strlen( lv_input ).
WHILE lv_length > lv_loop.
lv_digit = lv_input MOD 10.
lv_input = lv_input / 10.
lv_output = lv_digit * ( 2 ** lv_loop ).
lv_remain = lv_remain + lv_output .
lv_loop = lv_loop + 1.
ENDWHILE.
CLEAR: lv_loop , lv_output , lv_input, lv_digit.
WHILE lv_remain > 0.
lv_digit = lv_remain MOD 16.
IF lv_remain GE 16.
lv_remain = lv_remain DIV 16.
ELSE.
CLEAR lv_remain.
ENDIF.
CASE lv_digit.
WHEN 10.
lv_char = 'A'.
WHEN 11.
lv_char = 'B'.
WHEN 12.
lv_char = 'C'.
WHEN 13.
lv_char = 'D'.
WHEN 14.
lv_char = 'E'.
WHEN 15.
lv_char = 'F'.
WHEN OTHERS.
lv_char = lv_digit.
ENDCASE.
CONCATENATE lv_char lv_result INTO lv_result.
CONDENSE lv_result NO-GAPS.
ENDWHILE.
WRITE: 'Result in Hexa : ', lv_result.
2013 Oct 14 7:58 AM
Hi Chandra
Thnx for your reply.It is working correctly.
I appreciate for your quick help.
2013 Oct 14 8:07 AM
Frankly Speaking, I was not in mood to give you exact code. I want you to create by own using my old comment concept, it will clear your concepts .. But i saw you want it badly. So i shared ..
Good day
2024 Aug 22 7:31 PM
2013 Oct 14 5:43 AM
Hello Nagesh,
Please check the below link once, this might help you to solve your problem.
http://saptib.blogspot.in/2008/07/translate-hexadecimal-to-binary-to.html
Regards,
Anubhab