Click or drag to resize

Bin2I Function

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.10
Syntax
 FUNCTION Bin2I(
	cSignedInt AS STRING
) AS SHORT
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: Int16
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#
ptrHandle := FOpen2("sales.dbf", FO_READ)        // Point to byte 1 in the file
FSeek(ptrHandle, 1, FS_SET)                        // Read date of last update
siYear  := Bin2I(FReadStr(ptrHandle, 1) + _Chr(0))
siMonth := Bin2I(FReadStr(ptrHandle, 1) + _Chr(0))
siDay   := Bin2I(FReadStr(ptrHandle, 1) + _Chr(0))
? NTrim(siMonth), NTrim(siDay), NTrim(siYear)
FClose(ptrHandle)
See Also