Convert Harbour numeric into signed short encoded bytes
I2Bin( <nNumber> ) --> cBuffer
<nNumber> is a numeric value to convert (decimal digits are ignored).
I2Bin() return two bytes character string that contain 16 bit encoded signed short integer (least significant byte first).
I2Bin() is one of the low level binary conversion functions, those functions convert between Harbour numeric and a character representation of numeric value. I2Bin() take a numeric integer value and convert it into two bytes of encoded 16 bit signed short integer.
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).
I2Bin() is the opposite of Bin2I()
// Update DBF "last update" date #include "fileio.ch" PROCEDURE Main() LOCAL nHandle, cYear, cMonth, cDay USE test ? "Original update date is:", LUpdate() CLOSE nHandle := FOpen( "test.dbf", FO_READWRITE ) IF nHandle != F_ERROR FSeek( nHandle, 1 ) cYear := I2Bin( 68 ) cMonth := I2Bin( 8 ) cDay := I2Bin( 1 ) FWrite( nHandle, cYear , 1 ) // write only the first byte FWrite( nHandle, cMonth, 1 ) FWrite( nHandle, cDay , 1 ) FClose( nHandle ) USE test ? "New update date is:", LUpdate() CLOSE ELSE ? "Can not open file" ENDIF RETURN
This is CA-Cl*pper v5.2 compliant
Library is core
Bin2I(), Bin2L(), Bin2U(), Bin2W(), L2Bin(), W2Bin(), Word(), U2Bin(), FWrite()