I2Bin()

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"
      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

Compliance

Clipper

Files

Library is rtl

Seealso

BIN2I(), BIN2L(), BIN2U(), BIN2W(), L2BIN(), W2BIN(), WORD(), U2BIN(), FWRITE()

Advertisements

3 responses to “I2Bin()

  1. Pingback: Harbour All Functions – I | Viva Clipper !

  2. Pingback: Harbour Conversion Functions | Viva Clipper !

  3. Pingback: Harbour RG Summary | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s