Converts a 32-bit integer to an array of 4 bytes.
Public Declare Function CNV_NumToBytes Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByVal nNumber As Long, ByVal nOptions As Long) As Long
nRet = CNV_NumToBytes(lpOutput(0), nOutBytes, nNumber, nOptions)
long __stdcall CNV_NumToBytes(unsigned char *lpOutput, long nOutBytes, long nNumber, long nOptions);
If successful, the return value is zero; otherwise it returns a nonzero error code.
Public Function cnvNumToBytes (nNumber As Long, Optional nOptions As Long = 0) As Byte()
static bvec_t dipki::Cnv::NumToBytes (uint32_t n, EndianNess endn=EndianNess::BigEndian)
static Cnv.num_to_bytes(num, endn=EndianNess.BIG_ENDIAN)
The output byte array lpOutput will contain the representation of the integer in given order. A negative nNumber will be interpreted in equivalent twos-complement unsigned form.
Dim abData() As Byte
Dim nBytes As Long
Dim nNumber As Long
Dim nRet As Long
nBytes = 4
ReDim abData(nBytes - 1)
nNumber = &HDEADBEEF
Debug.Print "INPUT=0x" & Hex(nNumber) & " (" & nNumber & ")"
' Default big-endian order
nRet = CNV_NumToBytes(abData(0), nBytes, nNumber, 0)
Debug.Print "CNV_NumToBytes(BE)=" & cnvHexStrFromBytes(abData)
' Little-endian order
nRet = CNV_NumToBytes(abData(0), nBytes, nNumber, PKI_CNV_LITTLE_ENDIAN)
Debug.Print "CNV_NumToBytes(LE)=" & cnvHexStrFromBytes(abData)
INPUT=0xDEADBEEF (-559038737) CNV_NumToBytes(BE)=DEADBEEF CNV_NumToBytes(LE)=EFBEADDE
Dim lpData() As Byte
Dim nBytes As Long
Dim nNumber As Long
nNumber = &HDEADBEEF
Debug.Print "INPUT=0x" & Hex(nNumber) & " (" & nNumber & ")"
' Default big-endian order
lpData = cnvNumToBytes(nNumber)
Debug.Print "cnvNumToBytes(BE)=" & cnvHexStrFromBytes(lpData)
' Little-endian order
lpData = cnvNumToBytes(nNumber, PKI_CNV_LITTLE_ENDIAN)
Debug.Print "cnvNumToBytes(LE)=" & cnvHexStrFromBytes(lpData)