Function I2bin() Foundation

Converts a numeric value to 16 bit integer.

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

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

Description

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.

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

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

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

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

RETURN 

Feedback

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.