Function Bin2w() Foundation

Converts a 16 bit unsigned integer to a numeric value.

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

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

Description

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.

Examples
Bin2w()
// The example shows various results of Bin2w() 

PROCEDURE Main 
   ? 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 
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.