Click or drag to resize

Bin2I Function

X#
Convert a string containing a 16-bit signed integer to a short integer.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax
 FUNCTION Bin2I(
	cSignedInt AS STRING
) AS SHORT
Request Example View Source

Parameters

cSignedInt
Type: String
A 16-bit signed 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: Short
Remarks
Bin2I() is a conversion function that converts the first 2 bytes of a string to a short integer. Typical applications include reading foreign file types in their native format then saving, reading, decrypting, and transmitting long numeric data in their compressed binary form instead of in strings. Positive numbers with 2 digits or less will not save disk space when converted.
For numbers that fall between 0 and 255, you can use Chr() or _Chr(). The inverse of Bin2I() is I2Bin().
Examples
This example opens a database file using file functions and reads the date of last update (bytes 1-3).
The result is the same as LUpdate():
X#
1ptrHandle := FOpen2("sales.dbf", FO_READ)    // Point to byte 1 in the file
2FSeek(ptrHandle, 1, FS_SET)            // Read date of last update
3siYear  := Bin2I(FReadStr(ptrHandle, 1) + _Chr(0))
4siMonth := Bin2I(FReadStr(ptrHandle, 1) + _Chr(0))
5siDay   := Bin2I(FReadStr(ptrHandle, 1) + _Chr(0))
6? NTrim(siMonth), NTrim(siDay), NTrim(siYear)
7FClose(ptrHandle)
See Also