ToBitString Function

Converts the value of an expression to a specific numeric type and returns the internal bit representation of the number packed into a String value.

...ToBitString ( expression, type, big_endian )

Prerequisites

None

Parameters

expression

A required numeric expression whose value is converted.

type

A required keyword that determines how the numeric value is interpreted and how many bytes the output String will contain. Must be one of the following: Byte, Short, Integer, Single, Double.

big_endian

A required numeric expression that determines the order in which bytes in the String output are generated.  If the value is zero or False, the bytes are packed in "little-endian" order, which means the least significant bytes in the value appear first in the String (PC/Intel format). If the value is non-zero or True, the bytes are packed in "big-endian" order, which means the most significant bytes in the value appear first in the String (Motorola format).

Remarks

This function evaluates a numeric expression, converts the results to a specified numeric type and packs the bits of the value into a String that is returned. The numeric value is written in the bit format used to internally represent the specified numeric type.  Depending upon the type, the converted value may have 8, 16, 32, or 64-bits, which correspond to an output String that will consist of 1, 2, 4, or 8 bytes.

Table 19-103 describes the output of this function.

Table 19-103: ToBitString Function

Keyword Bytes Numeric Type Conversion

Byte

1

Unsigned 8-bit value from 0 to 255

Short

2

Signed 16-bit integer

Integer

4

Signed 32-bit integer

Single

4

Single-precision IEEE floating point

Double

8

Double-precision IEEE floating point

When more than one byte is returned, the order of the bytes in the resulting String is determined by the big_endian parameter. If this parameter is True, the first byte of the String is the most-significant byte in the value. This is the typical format for Motorola processors, e.g. PowerPC’s.  If it is False, the first byte of the String is the least-significant byte in the value. This is the normal format for PC’s (Intel processors).

Examples

Dim stg As String
stg = ToBitString(23, Byte, True) ' Packs hex 17
Console.Writeline(FromBitString(stg, Byte, True)) ' Prints 23

stg = ToBitString(-321, Short, True) ' Packs hex FE,BF
Console.Writeline(FromBitString(stg, Short, True)) ' Prints -321

stg = ToBitString(56720, Integer, True) ' Packs hex 0,0,DD,90
Console.Writeline(FromBitString(stg, Integer, True)) ' Prints 56720

stg = ToBitString(123.4, Single, True) ' Packs hex 42,F6,CC,CD
Console.Writeline(FromBitString(stg, Single, True)) ' Prints 123.4

stg = ToBitString(123.4, Double, True) ' Packs hex 40,5E,D9,99,99,99,99,9A
Console.Writeline(FromBitString(stg, Double, True)) ' Prints 123.4

See Also

Strings |FromBitString Function