Hi All,
I'd like to use standard .NET Int32 type to convert integer into hex representation (Int32.ToString('X4'))
Trouble is I cannot initialize in in C/AL?
If I create a variable of type DotNet System.Int32.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' I cannot initialize it in CAL. The line:
DotNetInt := DotNetInt.Int32;
gives an error : Assignment is not allowed for this variable.
Can I use Int32 type at all ?
Any other simple method to convert an int into hex ?
Slawek
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Answers
Constructor of Int32 in CAL: static [int Int32 :=] Int32();
BEGIN
WHILE(Number>0) DO BEGIN
Return := COPYSTR('0123456789ABCDEF',(Number MOD 16)+1,1) + Return;
Number := Number DIV 16;
END;
END;
PROCEDURE Hex2Int@1000000050(Hex@1000000000 : Code[16]) Return : BigInteger;
BEGIN
WHILE(Hex<>'') DO BEGIN
Return := Return*16 + STRPOS('0123456789ABCDEF',COPYSTR(Hex,1,1))-1;
Hex := DELSTR(Hex,1,1);
END;
END;
you're right, impossible to work with Int32 or Int64. But you can work around it:
Use an IntPtr: IntP DotNet System.IntPtr.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
IntP := IntP.IntPtr(1234);
MESSAGE('Dec-Value='+IntP.ToString+', Hex-Value='+IntP.ToString('X4'));
Also
IntP := IntP.IntPtr(CAL_Int);
works.
Oli
lynge, a side note: your solution is not exact equivalent of int32.ToString('X4')). int32.ToString('X4')) gives you 4 character long hex string, while yours not.
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03