Convert a string containing a 16-bit unsigned integer to a word.
XSharp.Core (in XSharp.Core.dll) Version: 2.2a
Syntax View Source
cUnsignedInt AS STRING
) AS WORD
public static ushort Bin2W(
- Type: String
A 16-bit unsigned integer represented as a string — least significant byte first. Only the first 2 bytes are used by the function; all others are ignored.
Bin2W() is a conversion function that converts the first 2 bytes of a string to a word. Typical applications include reading foreign file types in their native format then saving, reading, decrypting, and transmitting numeric data in their compressed binary form instead of in strings. Its inverse is W2Bin().
This example opens a database file using file functions and reads the number of bytes per record (bytes 10-11). The result is the same as RecSize():
ptrHandle := FOpen2("sales.dbf", FO_READ)
// Note: The length of a record in sales.dbf is 124
// Point to byte 10, the first record size byte
FSeek(ptrHandle, 10, FS_SET)
cRecSize := Space(2) // Read record size
FRead(ptrHandle, @cRecSize, 2)
? NTrim(Bin2W(cRecSize))) // 124