Function I2bin() Foundation

Converts a numeric value to 16 bit integer.

I2bin( <nInteger> ) --> cBinary
<nInteger> is a numeric expression whose value is converted into binary format. When the value is not an integer, the decimal places are truncated.

The return value of I2bin() is a character string of two characters containing the numeric value as a 16 bit integer.


I2bin() converts numeric values in the range of -32768 to +32767 to their binary representation. The function returns a character string of two characters, where the first character represents the lower value byte. I2bin() ignores decimal places and converts only the integer portion of a number. The counterpart of I2bin() is Bin2i().

I2Bin() is frequently used in connection with the low level file functions. This is sometimes done to allow definition of a special or unique file formats, or to provide a data compression technique for integer values.

Data compression with I2bin()
// The example demonstrates a simple process of 
// data compression for numeric values whose value range 
// is known. 

   LOCAL i, cNumeric:="", cCompressed := "" 

   FOR i:=1 TO 10000 
      cNumeric    += Str( i , 5 ) 
      cCompressed += I2bin( i ) 

   ? Len( cNumeric )           // result: 50000 
   ? Len( cCompressed )        // result: 20000 



If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.