Convert Int to Hex and vice versa with DotNet

oki
Member Posts: 46
You can use DotNet functionality to do the job for you.
1.) Variable Declarations used in the following examples:
2.) Conversion from Integer to Hexadecimal
Because System.Int32 and System.Int64 variables cannot neither be assigned a value nor constructed in CA/L, the System.IntPtr must be used:
3.) Conversion from Integer to Hexadecimal
Here we can use the System.Int32 and System.Int64 because we only use the Parse method.
Little watch is needed here using the right size type.
Have fun
1.) Variable Declarations used in the following examples:
Name DataType Subtype LInt32 DotNet System.Int32.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' LInt64 DotNet System.Int64.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' LIntP DotNet System.IntPtr.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' NumStyles DotNet System.Globalization.NumberStyles.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' i Integer bi BigInteger s Text
2.) Conversion from Integer to Hexadecimal
Because System.Int32 and System.Int64 variables cannot neither be assigned a value nor constructed in CA/L, the System.IntPtr must be used:
// let LIntP point on value or variable, where the variable can be Integer or BigInteger LIntP := LIntP.IntPtr(<int value or CA/L-int variable>); // let s get the hexadecimal representaion of the integer above, filled with preceeding zeroes if hex-number has less than 4 digits s := LIntP.ToString('X4'); MESSAGE('Int To Hex:\Int-Value='+LIntP.ToString+', Hex-Value='+s);
3.) Conversion from Integer to Hexadecimal
Here we can use the System.Int32 and System.Int64 because we only use the Parse method.
Little watch is needed here using the right size type.
s := '1DC942DE'; i := LInt32.Parse(s, NumStyles.HexNumber); MESSAGE('Hex To Int (32bit)\Hex-Value=%1, Int-Value=%2',s,i); s := 'FDC96EDBFFFFFFFF'; bi := LInt64.Parse(s, NumStyles.HexNumber); MESSAGE('Hex To Int (64bit)\Hex-Value=%1, Int-Value=%2',s,bi);
Have fun

2
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions