Function Bin2w() Foundation

Converts a 16 bit unsigned integer to a numeric value.

Bin2w( <cUnsignedInt> ) --> nUnsignedInt
<cUnsignedInt> is a character string whose first two bytes (characters) are converted to a 16 bit unsigned integer.

The conversion function Bin2w() returns an integer numeric value in the range of 0 to 65535.


Bin2w() converts binary numbers within character strings to their numeric values. The counterpart of Bin2w() is the function W2bin() which converts a positive integer to a 2 byte character string.

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

Bin2w() is 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 read files whose data is in binary format.

// The example shows various results of Bin2w() 

   ? Bin2w( Chr(0)+Chr(0) )      // result:      0 
   ? Bin2w( Chr(1)+Chr(0) )      // result:      1 
   ? Bin2w( Chr(2)+Chr(0) )      // result:      2 

   ? Bin2w( Chr(255)+Chr(0) )    // result:    255 
   ? Bin2w( Chr(255)+Chr(1) )    // result:    511 
   ? Bin2w( Chr(255)+Chr(2) )    // result:    767 

   ? Bin2w( Chr(0)+Chr(255) )    // result:  65280 
   ? Bin2w( Chr(1)+Chr(255) )    // result:  65281 
   ? Bin2w( Chr(2)+Chr(255) )    // result:  65282 

   ? Bin2w( Chr(255)+Chr(255) )  // result:  65535 

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.