xHarbour Reference Documentation > Function Reference |
Converts a numeric value to a signed short binary integer (2 bytes).
I2Bin( <nNumber> ) --> cInteger
The function returns a two-byte character string representing a 16-bit signed short binary integer.
I2Bin() is a binary conversion function that converts a numeric value (Valtype()=="N") to a two byte binary number (Valtype()=="C").
The range for the numeric return value is determined by a signed short integer. If <nNumber> is outside this range, a runtime error is raised.
I2Bin() is the inverse function of Bin2I().
See also: | Asc(), Bin2I(), Bin2L(), Bin2U(), Bin2W(), Chr(), L2Bin(), U2Bin(), W2Bin() |
Category: | Binary functions , Conversion functions |
Source: | rtl\binnum.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates return values of I2Bin(). PROCEDURE Main LOCAL cInt cInt := I2Bin(0) ? Asc( cInt[1] ), Asc( cInt[2] ) // result: 0 0 cInt := I2Bin(1) ? Asc( cInt[1] ), Asc( cInt[2] ) // result: 1 0 cInt := I2Bin(-1) ? Asc( cInt[1] ), Asc( cInt[2] ) // result: 255 255 cInt := I2Bin(256) ? Asc( cInt[1] ), Asc( cInt[2] ) // result: 0 1 cInt := I2Bin(-256) ? Asc( cInt[1] ), Asc( cInt[2] ) // result: 0 255 cInt := I2Bin(32767) ? Asc( cInt[1] ), Asc( cInt[2] ) // result: 255 127 cInt := I2Bin(-32768) ? Asc( cInt[1] ), Asc( cInt[2] ) // result: 0 128 RETURN
http://www.xHarbour.com