CryptoSys PKI Pro Manual

CNV_NumToBytes

Converts a 32-bit integer to an array of 4 bytes.

VBA/VB6 Syntax

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)

C/C++ Syntax

long __stdcall CNV_NumToBytes(unsigned char *lpOutput, long nOutBytes, long nNumber, long nOptions);

Parameters

lpOutput
[out] byte array to receive output.
nOutBytes
[in] size of output array in bytes.
nNumber
[in] integer to be converted.
nOptions
[in] Option flags. Select one of:
PKI_CNV_BIG_ENDIAN (0) for big-endian order (default)
PKI_CNV_LITTLE_ENDIAN for little-endian order

Returns (VBA/C)

If successful, the return value is zero; otherwise it returns a nonzero error code.

VBA Wrapper Syntax

Public Function cnvNumToBytes (nNumber As Long, Optional nOptions As Long = 0) As Byte()

.NET Equivalent

Cnv.NumToBytes Method

C++ (STL) Equivalent

static bvec_t dipki::Cnv::NumToBytes (uint32_t n, EndianNess endn=EndianNess::BigEndian)

Python Equivalent

static Cnv.num_to_bytes(num, endn=EndianNess.BIG_ENDIAN)

Remarks

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.

Example (VBA core function)

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

Example (VBA wrapper function)

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)

See Also

CNV_NumFromBytes

[Contents] [Index]

[PREV: CNV_NumFromBytes...]   [Contents]   [Index]   
   [NEXT: CNV_ReverseBytes...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.