Click or drag to resize

Bin2W Function

X#
Convert a string containing a 16-bit unsigned integer to a word.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.21
Syntax
 FUNCTION Bin2W(
	cUnsignedInt AS STRING
) AS WORD
Request Example View Source

Parameters

cUnsignedInt
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.

Return Value

Type: Word
Remarks
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().
Examples
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():
X#
1ptrHandle := FOpen2("sales.dbf", FO_READ)
2// Note: The length of a record in sales.dbf is 124
3// Point to byte 10, the first record size byte
4FSeek(ptrHandle, 10, FS_SET)
5cRecSize := Space(2)            // Read record size
6FRead(ptrHandle, @cRecSize, 2)
7? NTrim(Bin2W(cRecSize)))            // 124
8FClose(ptrHandle)
See Also