CryptoSys PKI Pro Manual

CNV_NumFromBytes

Converts the leftmost four bytes of an array to a 32-bit integer.

VBA/VB6 Syntax

Public Declare Function CNV_NumFromBytes Lib "diCrPKI.dll" (ByRef lpInput As Byte, ByVal nBytes As Long, ByVal nOptions As Long) As Long

nRet = CNV_NumFromBytes(lpInput(0), nBytes, nOptions)

C/C++ Syntax

long __stdcall CNV_NumFromBytes(const unsigned char *lpInput, long nBytes, long nOptions);

Parameters

lpInput
[in] Byte array to be converted.
nBytes
[in] number of bytes.
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)

Decoded integer value, or zero on error.

VBA Wrapper Syntax

Public Function cnvNumFromBytes (lpInput() As Byte, Optional nOptions As Long = 0) As Long

.NET Equivalent

Cnv.NumFromBytes Method

C++ (STL) Equivalent

static uint32_t dipki::Cnv::NumFromBytes (const bvec_t &bv, EndianNess endn=EndianNess::BigEndian)

Python Equivalent

static Cnv.num_from_bytes(data, endn=EndianNess.BIG_ENDIAN)

Remarks

An array shorter than 4 bytes will be padded on the right with zeros.

Example

Dim abData() As Byte
Dim nBytes As Long
Dim nRet As Long

abData = cnvBytesFromHexStr("DEADBEEF")
nBytes = UBound(abData) + 1
Debug.Print "INPUT:  " & cnvHexStrFromBytes(abData)
' Default big-endian order
nRet = CNV_NumFromBytes(abData(0), nBytes, 0)
Debug.Print "CNV_NumFromBytes(BE)=0x" & Hex(nRet)
' Little-endian order
nRet = CNV_NumFromBytes(abData(0), nBytes, PKI_CNV_LITTLE_ENDIAN)
Debug.Print "CNV_NumFromBytes(LE)=0x" & Hex(nRet)
' Input shorter than 4 bytes is padded on the right with zeros
nRet = CNV_NumFromBytes(abData(0), 3, PKI_CNV_BIG_ENDIAN)
Debug.Print "CNV_NumFromBytes(BE)=0x" & Hex(nRet)
nRet = CNV_NumFromBytes(abData(0), 3, PKI_CNV_LITTLE_ENDIAN)
Debug.Print "CNV_NumFromBytes(LE)=0x" & Hex(nRet)
INPUT:  DEADBEEF
CNV_NumFromBytes(BE)=0xDEADBEEF
CNV_NumFromBytes(LE)=0xEFBEADDE
CNV_NumFromBytes(BE)=0xDEADBE00
CNV_NumFromBytes(LE)=0xBEADDE

See Also

CNV_NumToBytes

[Contents] [Index]

[PREV: CNV_Latin1FromUTF8Bytes...]   [Contents]   [Index]   
   [NEXT: CNV_NumToBytes...]

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