Click or drag to resize

I2Bin Function

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

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

Parameters

siValue
Type: Short
The value to convert. Decimal digits are truncated.

Return Value

Type: String
Remarks
I2Bin() is a conversion function that converts a short integer to a 2-byte string. Typical applications include reading foreign file types in their native format and then saving, reading, decrypting, and transmitting numeric data in their compressed binary form instead of in strings.
Its inverse is Bin2I().
Examples
This example opens a database file using file functions and writes a new date of the last update to bytes 1-3:
X#
 1ptrHandle = FOpen2("sales.dbf", FO_READWRITE)
 2// Convert date of last update to int
 3cYear := I2Bin(1990)
 4// The more efficient _Chr() is used instead of
 5// I2Bin() since the return fits in one byte
 6cMonth := _Chr(12)
 7cDay := _Chr(15)
 8// Point to the date of last update
 9FSeek(ptrHandle, 1, FS_SET)
10// Write new update date using only the first
11// byte
12FWrite3(ptrHandle, cYear, 1)
13FWrite3(ptrHandle, cMonth, 1)
14FWrite3(ptrHandle, cDay, 1)
15FClose(ptrHandle)
See Also