Does anyone have a routine handy (or know of an API) that will convert
hex characters to decimal or integer?
After having read the good alternatives given, I still want to provide
another one, pretty simple and useful too:
**************************************************************
D bin2hex PR 10I 0 ExtProc('sprintf')
D hexMap 17A
D fmtStr * Value Options(*String)
D binMap 20U 0 VALUE OPTIONS(*NOPASS)
**
D hex2bin PR 10I 0 ExtProc('sscanf')
D hexMap 17A
D fmtStr * Value Options(*String)
D binMap 20U 0 Options(*NOPASS)
******************************************************
bin2hex takes an unsigned 64-bit integer and will "printf" its hexadecimal
human-readable representation into the hexMap variable.
Usage would be similar to:
bin2hex(cTempBitMap: // variable to receive output including a \x00
'%016llX': // format to print out
bPriBitMap); // 64-bit unsigned variable
On the other hand, the opposite, hex2Bin will scan a human-readable
hexadecimal expression of a 64-bit variable and will convert it into an
unsigned 64-bit integer:
hex2bin(cTempBitMap: // a 17-byte char variable includes a null char
'%016llX': // format to scan
bSecBitMap); // reference (or pointer) to the 64-bit unsigned
integer
Hope this could help anyway.
Javier Sanchez
As an Amazon Associate we earn from qualifying purchases.