Page 1 of 1
Using AsHexString
Posted: Tue Dec 03, 2024 9:54 pm
by MARCOREMMEDATA
Hi
I've to convert a integer value in Hexadecimal. But intrincic function AsHexString give back a wrong value.
can you help me understand if I am using the function incorrectly?
The value is 49202, Window Calc for HEX is C032 for lansa il 32C00000
https://docs.lansa.com/14/en/lansa016/P ... STRING.htm
Re: Using AsHexString
Posted: Wed Dec 04, 2024 5:12 am
by chriskarge
Howdy! Agreed, it looks like the intrinsic method doesn't work. I created a quick form / routine to do the conversion; it isn't very elegant, but the uDec2Hex routine seems to return the correct value, so maybe you can use it as a starting point?
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientwidth(484) Clientheight(301) Componentversion(2)
Define_Com Class(#STD_NUM.Visual) Name(#STD_NUM) Componentversion(1) Displayposition(1) Height(21) Left(17) Parent(#COM_OWNER) Tabposition(1) Top(23) Usepicklist(False) Width(352)
Define_Com Class(#STD_TEXT.Visual) Name(#STD_TEXT) Componentversion(1) Displayposition(2) Height(21) Left(17) Parent(#COM_OWNER) Tabposition(2) Top(55) Usepicklist(False) Width(895)
Define_Com Class(#PRIM_PHBN) Name(#Button1) Caption('Button1') Displayposition(3) Left(360) Parent(#COM_OWNER) Tabposition(3) Top(122) Buttondefault(True)
Evtroutine Handling(#com_owner.CreateInstance)
Set Com(#com_owner) Caption(*component_desc)
Endroutine
Evtroutine Handling(#Button1.Click)
#Com_Owner.uDec2Hex Inumber(#STD_NUM) Ohexstring(#STD_TEXT)
Endroutine
Mthroutine Name(uDec2Hex) Access(*PRIVATE)
Define_Map For(*INPUT) Class(#STD_NUM) Name(#INumber) Desc('Number to convert to hex')
Define_Map For(*OUTPUT) Class(#STD_TEXT) Name(#OHexString) Desc('Number converted to hex')
*
Define Field(#W_Remain) Type(*DEC) Length(9) Decimals(0) Desc('Remainder / Index to Array')
Define Field(#W_HexChar) Type(*CHAR) Length(16) Desc('Array of hexadecimal digits') Default('0123456789ABCDEF')
*
#OHexString := *NULL
*
If_Null Field(#INumber)
#OHexString := '0'
Else
Dowhile Cond('(#INumber *GT *ZERO)')
* Remainder (plus 1) is index to array
#W_Remain := #INumber.Mod( 16 ) + 1
* Assemble hex string by placing character in front of any previously calculated characters
#OHexString := #W_HexChar.Substring( #W_Remain 1 ) + #OHexString
* Calculate quotient for next operation
#INumber := #INumber / 16
Endwhile
Endif
Endroutine
End_Com
HTH, Chris
Re: Using AsHexString
Posted: Fri Dec 06, 2024 8:26 pm
by MARCOREMMEDATA
Hi
thank you.
I realised that the intrinsic function works but in reverse. The Hex string is inverted for pairs of characters
In a old Lansa newsletter
https://lansa.com/downloads/support/new ... feb10e.pdf pag 19
Int: 49202, Window Calc for HEX: C0 32; lansa: 32 C0
Int:169999999999, Windows Calc for HEX: 27 94 CA 23 FF; lansa: FF 23 CA 94 27
I solved it by reversing the string
Code: Select all
DEFINE FIELD(#CC) TYPE(*DEC) LENGTH(3) DECIMALS(0)
DEFINE FIELD(#CRC) REFFLD(#RTE_PNPDU)
DEFINE FIELD(#REVERTCRC) REFFLD(#RTE_PNPDU)
DEF_ARRAY NAME(#REV) INDEXES(#CC) OVERLAYING(#REVERTCRC) TYPE(*CHAR) ENTRY_LEN(2)
#REVERTCRC := ( 49202 ).AsBinString.AsHexString
#CRC := ""
BEGIN_LOOP USING(#CC) FROM(128) TO(1) STEP(-1)
CONTINUE IF((#REV#CC = '00') *Or (#REV#CC = ''))
#CRC += #REV#CC
END_LOOP
Re: Using AsHexString
Posted: Sat Dec 07, 2024 12:29 am
by chriskarge
Howdy!
I noticed the octets seemed to be reversed as well. Personally, I would not use the code to reverse the errant values because you never know when LANSA might provide a correction to the intrinsic method in an EPC/upgrade, which would then cause the application to start returning incorrect results. That's just my opinion though.
Take care!
Re: Using AsHexString
Posted: Sat Dec 07, 2024 10:43 am
by Dino
Fix maybe a hot fix, clearly a defect, if you are in maintenance, try to get that. That will solve the issue for you and everyone trying to use the same intrinsic