Convert a string containing a 16-bit signed integer to a short integer.
XSharp.Core (in XSharp.Core.dll) Version: 2.2a
Syntax View Source
cSignedInt AS STRING
) AS SHORT
public static short Bin2I(
- 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.
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().
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():
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)