I2BIN()
Convert Harbour numeric into signed short encoded bytes
- Syntax
-
- I2BIN( <nNumber> ) --> cBuffer
- Arguments
-
- <nNumber> is a numeric value to convert (decimal digits are ignored).
- Returns
-
- I2BIN() return two bytes character string that contain 16 bit encoded signed short integer (least significant byte first).
- Description
-
- 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()
Examples
// Update DBF "last update" date
#include "fileio.ch"
FUNCTION main()
LOCAL nHandle, cYear, cMonth, cDay
use test
? "Original update date is:", lupdate()
close
nHandle := fopen( "test.dbf", FO_READWRITE )
IF nHandle > 0
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 NIL
- Status
- Ready
- Compliance
-
- I2BIN() works exactly like CA-Clipper's I2BIN()
- Files
-
- Library is rtl
- See Also