Click or drag to resize

I2Bin Function

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.10
Syntax
 FUNCTION I2Bin(
	siValue AS SHORT
) AS STRING
View Source

Parameters

siValue
Type: Int16
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#
ptrHandle = FOpen2("sales.dbf", FO_READWRITE)
// Convert date of last update to int
cYear := I2Bin(1990)
// The more efficient _Chr() is used instead of
// I2Bin() since the return fits in one byte
cMonth := _Chr(12)
cDay := _Chr(15)
// Point to the date of last update
FSeek(ptrHandle, 1, FS_SET)
// Write new update date using only the first
// byte
FWrite3(ptrHandle, cYear, 1)
FWrite3(ptrHandle, cMonth, 1)
FWrite3(ptrHandle, cDay, 1)
FClose(ptrHandle)
See Also