BitConverter: GetBytes

GetBytes

Returns a byte array representation of the datatype value.



 Public Function GetBytes(
	  ByRef Value As Variant ) As Byte ( )

Parameters

Value
[ByRef] Variant. The datatype to be converted to a byte array.

Return Values

Byte() -  An array of bytes converted from the bits of the original datatype.

Remarks

A type boolean is converted to one byte. If the boolean value is True, then the byte is 1, otherwise, it is 0.

The byte array contains as many bytes as the length of the datatype being converted. A Long returns a 4-byte array, where as a Double will return an 8-byte array.

The following is a list of types that are supported.

The Decimal type is converted to 16 bytes with the same layout as used in .NET. The layout is different than that of Visual Basic.

The differing layouts is shown in the following table.

FrameworkLayout
Visual Basic bytes 0-1: Variant type information (Decimal has value 14)
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 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)

See Also

Project CorLib Overview

Class BitConverter Overview