I had a look at wikipedia article on MEID format and it gave required information.
You want to convert 99000124997700 to 256691434010057472.
99000124base16 = 2566914340base10
997700base16 = 10057472base10
Concatenating base10 numbers gives 256691434010057472.
Theory:
Split the hex number into 2 parts, length 8 and length 6.
Convert those parts to decimal, and then concatenate the parts.
Code:
The code is not straightforward. Reason being the integer variable is of 2 bytes, and it can't store big enough numbers like 2566914340.
I had written a document on how to handle Integer Arithmetic Operations on Large Numbers
Below code snippet is using same class given in my document, and it is able to give correct answer.
After looking at how it works, you can clean and optimize it.
Note: Padding zeros on left side of parts may be required.
- START-OF-SELECTION.
- DATA meid_hex TYPE string VALUE'99000124997700'.
- DATA meid_dec TYPE string.
- DATA temp TYPE string.
- DATA lr_dec TYPEREFTO lcl_bignum.
- DATA lr_16 TYPEREFTO lcl_bignum. "fix value for base 16
- DATA lr_power TYPEREFTO lcl_bignum.
- DATA lr_multiplier TYPEREFTO lcl_bignum.
- DATA lr_digit TYPEREFTO lcl_bignum.
- DATA lr_tempdec TYPEREFTO lcl_bignum.
- DATA offset TYPEi.
- offset = 13. "13th character is last for hex meid
- TRY .
- CREATE OBJECT lr_dec.
- CREATE OBJECT lr_16.
- CREATE OBJECT lr_power.
- CREATE OBJECT lr_multiplier.
- CREATE OBJECT lr_digit.
- CREATE OBJECT lr_tempdec.
- * initialize the base16 value
- lr_16->set_data( '16' ).
- DO14TIMES.
- *calculate decimal multiplier based on hex position
- * decimal number 123 = 1 * 10^2 + 2 * 10^1 + 3 * 10^0
- * decimal equalant of hex number 543 = 5 * 16^2 + 4 * 16^1 + 3 * 16^0
- temp = sy-index - 1.
- lr_power->set_data( temp ).
- lr_multiplier->power( i_obj1 = lr_16
- i_obj2 = lr_power ).
- * we loop from last hex digit to first hex digit
- temp = meid_hex+offset(1).
- lr_digit->set_data( temp ).
- lr_tempdec->multiply( i_obj1 = lr_multiplier
- i_obj2 = lr_digit ).
- * add digit including its weight to final decimal result
- lr_dec->add( i_obj1 = lr_dec
- i_obj2 = lr_tempdec ).
- * temp = lr_dec->get_string( ).
- * WRITE:/ offset, temp.
- * number = number + meid_hex+offset(1) * ( 16 ** ( sy-index - 1 ) ).
- offset = offset - 1.
- ENDDO.
- lr_power->set_data( '6' ).
- lr_multiplier->power( i_obj1 = lr_16
- i_obj2 = lr_power ).
- lr_tempdec->divide( i_obj1 = lr_dec
- i_obj2 = lr_multiplier ).
- * get part1
- meid_dec = lr_tempdec->get_string( ).
- * get part2
- lr_tempdec->mod( i_obj1 = lr_dec
- i_obj2 = lr_multiplier ).
- temp = lr_tempdec->get_string( ).
- CONCATENATE meid_dec temp INTO meid_dec.
- WRITE:/ meid_dec.
- CATCH cx_root.
- ENDTRY.
/.