Functions and Directives

Function Bin2l() Foundation

Converts a 32 bit signed integer (long) to a numeric value.

Bin2l( <cSignedInt> ) --> nSignedInt
<cSignedInt> is a character string whose first four bytes (characters) are converted to a 32 bit signed integer.

The conversion function Bin2l() returns an integer numeric value in the range of -2147483648 to +2147483647.


Bin2l() converts a binary number within a character string to its numeric value. The counterpart of Bin2l() is the function L2bin(), which converts a signed integer to a 4 byte long character string.

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

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

Bin2l() and Bin2i()
// In this example binary information is read from the 
// header of a DBF file with low level file functions 
// and converted to numeric values. 

#include "" 

   LOCAL nHandle, cBytes 

   nHandle := FOpen("Address.dbf") // DBF with 226 file records 
   FSeek( nHandle, 1, FS_SET ) 

   cBytes  := Space(1) 
   FRead( nHandle, @cBytes, 1)      // year of the last update 
   ? Asc( cBytes )                  // result: 94 

   FRead( nHandle, @cBytes, 1 )     // month of the last update 
   ? Asc( cBytes )                  // result: 12 

   FRead( nHandle, @cBytes, 1 )     // day of the last update 
   ? Asc( cBytes )                  // result: 6 

   cBytes  := Space( 4 ) 
   FRead( nHandle, @cBytes, 4 )     // number of data records 
   ? Bin2l( cBytes )                // result: 226 

   cBytes  := Space( 2 ) 
   FRead( nHandle, @cBytes, 2 )     // length of the file header 
   ? Bin2i( cBytes )                // result: 897 

   FRead( nHandle, @cBytes, 2 )     // length of a data record + 1 
   ? Bin2i( cBytes )                // result: 368 

   FClose( nHandle ) 


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.