Convert a string containing a 16-bit signed integer to a short integer.
XSharp.Core (in XSharp.Core.dll) Version: 2.18
Syntax Request Example
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():
1ptrHandle := FOpen2("sales.dbf", FO_READ)
2FSeek(ptrHandle, 1, FS_SET)
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)