Convert unsigned short encoded bytes into Harbour numeric
Bin2W( <cBuffer> ) --> nNumber
<cBuffer> is a character string that contain 16 bit encoded unsigned short integer (least significant byte first). The first two bytes are taken into account, the rest if any are ignored.
Bin2W() return numeric integer (or 0 if <cBuffer> is not a string).
Bin2W() is one of the low level binary conversion functions, those functions convert between Harbour numeric and a character representation of numeric value. Bin2W() take two bytes of encoded 16 bit unsigned short integer and convert it into standard Harbour numeric value.
You might ask what is the need for such functions, well, first of all it allow you to read/write information from/to a binary file (like extracting information from DBF header), it is also a useful way to share information from source other than Harbour (C for instance).
Bin2W() is the opposite of W2Bin()
// Show header length of a DBF #include "fileio.ch" PROCEDURE Main() LOCAL nHandle, cBuffer := Space( 2 ) nHandle := FOpen( "test.dbf" ) IF nHandle != F_ERROR FSeek( nHandle, 8 ) FRead( nHandle, @cBuffer, hb_BLen( cBuffer ) ) ? "Length of DBF header in bytes:", Bin2W( cBuffer ) FClose( nHandle ) ELSE ? "Can not open file" ENDIF RETURN
This is CA-Cl*pper v5.2 compliant
Library is core
Bin2I(), Bin2L(), Bin2U(), I2Bin(), L2Bin(), W2Bin(), Word(), U2Bin(), FRead()