Function Bin2i() Foundation

Converts a signed 16 bit integer to a numeric value.

Syntax
Bin2i( <cSignedInt> ) --> nSignedInt
Parameters
<cSignedInt>
<cSignedInt> is a character string whose first two bytes (characters) are converted to a 16 bit signed integer.
Return

The conversion function Bin2i() returns an integer numeric value in the range of -32768 to +32767.

Description

Bin2i() converts binary numbers in a character string to their numeric value. The counterpart of Bin2i() is the function I2bin() which converts a signed integer to a 2 byte character string.

The value range of Bin2i() or I2bin() is that of a 16 bit signed integer. Similar conversion functions are Bin2w(), Bin2l() and Bin2u().

Bin2i() and I2bin() are frequently used in connection with the low level file functions. This is sometimes done to allow definition of special or unique file formats, or to provide data compression when integer numeric values are being stored.

Examples
Bin2i()
// The example shows various results of the function Bin2i() 

PROCEDURE Main 

   ? Bin2i( Chr(255)+Chr(127) )     // result:  32767 
   ? Bin2i( Chr(254)+Chr(127) )     // result:  32766 
   ? Bin2i( Chr(253)+Chr(127) )     // result:  32765 

   ? Bin2i( Chr(255)+Chr(126) )     // result:  32511 
   ? Bin2i( Chr(255)+Chr(125) )     // result:  32255 
   ? Bin2i( Chr(255)+Chr(124) )     // result:  31999 

   ? Bin2i( Chr(0)+Chr(128) )       // result: -32768 
   ? Bin2i( Chr(1)+Chr(128) )       // result: -32767 
   ? Bin2i( Chr(2)+Chr(128) )       // result: -32766 

   ? Bin2i( Chr(0)+Chr(129) )       // result: -32512 
   ? Bin2i( Chr(0)+Chr(130) )       // result: -32256 
   ? Bin2i( Chr(0)+Chr(131) )       // result: -32000 

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.