Decodes a hexadecimal-encoded string into an array of Bytes.
Public Declare Function CNV_BytesFromHexStr Lib "diCryptoSys.dll"
(ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strInput As String) As Long
nRet = CNV_BytesFromHexStr(abData(0), nDataLen, strInput)
long __stdcall CNV_BytesFromHexStr(unsigned char *lpOutput, long nOutputLen, const char *szInput);
If successful, the return value is the number of bytes in the decoded array; otherwise it returns a negative error code.
Public Function cnvBytesFromHexStr
(szHex As String) As Byte()
conv.BytesFromHex
Public Function BytesFromHex(ByVal strHex As String) As Variant
See conv.BytesFromHex
.
static bvec_t crsysapi::Cnv::FromHex (const std::string &s)
static Cnv.fromhex(s)
Call the function with a zero nOutBytes or NULL lpOutput array to find the required length.
@warning [Changed in v5.2] This function now returns an error if it finds an illegal character in the input string
(previously any non-hex character was just ignored).
Whitespace characters and ASCII punctuation characters are still allowed and ignored (so "DE:AD:BE:EF"
is OK)
but obviously non-hex characters like those in the range [G-Zg-z]
will cause an error.
Dim strHex As String Dim abData() As Byte Dim i As Integer strHex = "FEDCAB9876543210" ' Convert hex string to bytes abData = cnvBytesFromHexStr(strHex) Debug.Print "{"; For i = LBound(abData) To UBound(abData) Debug.Print Hex(abData(i)) & ", "; Next Debug.Print "}" strHex = "" ' Convert back to a hex string strHex = cnvHexStrFromBytes(abData) Debug.Print strHex
Output:
{FE, DC, AB, 98, 76, 54, 32, 10, } FEDCAB9876543210
CNV_HexStrFromBytes
CNV_HexFilter