BitConverter: ToDecimal

ToDecimal

Converts an array of bytes do a Variant Decimal value.



 Public Function ToDecimal(
	  ByRef Bytes ( ) As Byte,
	  ByVal startIndex As Long ) As Variant

Parameters

Bytes
[ByRef] Byte. The array of bytes used to create a Decimal value. Must be atleast 16 bytes in length.
startIndex
[ByVal] Long. The starting index within the array to be converting to a Decimal value.

Return Values

Variant -  The converted Decimal value.

Remarks

The Decimal datatype is created from 16 bytes with the same layout as used in .NET. The layout is different than that of VB.

VB Decimal layout
bytes 0-1: Variant datatype information
bytes 2: precision
bytes 3: sign (&H80 is negative)
bytes 4-7: the 32 highest bits in the 96bit value
bytes 8-11: the 32 lowest bits in the 96bit value
bytes 12-15: the 32 middle bits in the 96bit value

.NET Decimal layout
bytes 0-3: the 32 lowest bits in the 96bit value
bytes 4-7: the 32 middle bits in the 96bit value
bytes 8-11: the 32 highest bits in the 96bit value
bytes 12-13: unused (zero)
bytes 14: precision
bytes 15: sign (&H80 is negative)

If the sign byte is non-zero, then the Decimal will be set as negative.

See Also

Project VBCorLib Overview Class BitConverter Overview BitConverter Properties BitConverter Methods ToDate ToDouble