FromBitString Function

Extracts a number that has been packed in its internal bit format into a String and returns the value of the number.

...FromBitString ( string, type, big_endian )

Prerequisites

None

Parameters

string

A required String expression whose 8-bit characters contain a sequence of bits that are converted according to the type parameter to produce the returned numeric value. The minimum length of this String depends on the type parameter.

type

A required keyword that determines how the bit sequence in the string parameter is interpreted. 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 parameter are processed.  If the value is zero or False, the bytes are assumed to be 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 assumed to be in "big-endian" order, which means the most significant bytes in the value appear first in the String (Motorola format).

Remarks

This function operates on a String that contains a numeric value that has been packed in a internal number format.  This function extracts the value of the packed number by converting the bits in the string according to the type specification. The 8-bit characters in the string are concatenated together to form an 8, 16, 32, or 64-bit internal representation of the number.  The interpretation of the type parameter and the required number of bytes in the string are presented in Table 19-101.

Table 19-101: FromBitString Function

Keyword Bytes Returned Value

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

The first byte of the string and any required successive bytes are used to obtain the bits. The string parameter must be at least as long as the number of bytes required for the data type.

When more than one byte is required, the order in which the bytes were packed into the string is specified 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 such as PowerPC's. If this parameter 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 |ToBitString Function