Click or drag to resize

Bin2W Function

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

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.2a
Syntax
 FUNCTION Bin2W(
	cUnsignedInt AS STRING
) AS WORD
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: UInt16
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#
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
FClose(ptrHandle)
See Also