/* $DOC$
   $AUTHOR$
      Copyright 2000 Chen Kedem <niki@actcom.co.il>
   $TEMPLATE$
      Function
   $NAME$
      Bin2I()
   $CATEGORY$
      API
   $SUBCATEGORY$
      Conversion
   $ONELINER$
      Convert signed short encoded bytes into Harbour numeric
   $SYNTAX$
      Bin2I( <cBuffer> ) --> nNumber
   $ARGUMENTS$
      <cBuffer> is a character string that contains 16-bit encoded signed
      short integer (least significant byte first). The first two bytes
      are taken into account, the rest if any are ignored.
   $RETURNS$
      Bin2I() return numeric integer (or 0 if <cBuffer> is not a string).
   $DESCRIPTION$
      Bin2I() is one of the low-level binary conversion functions, those
      functions convert between Harbour numeric and a character
      representation of numeric value. Bin2I() take two bytes of encoded
      16-bit signed 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).

      Bin2I() is the opposite of I2Bin()
   $EXAMPLES$
      // Show DBF last update date
      #include "fileio.ch"
      LOCAL hFile, cYear, cMonth, cDay
      IF ( hFile := hb_vfOpen( "test.dbf", FO_READ ) ) != NIL
         hb_vfSeek( hFile, 1 )
         cYear := cMonth := cDay := hb_BChar( 0 )
         hb_vfRead( hFile, @cYear , hb_BLen( cYear ) )
         hb_vfRead( hFile, @cMonth, hb_BLen( cMonth ) )
         hb_vfRead( hFile, @cDay  , hb_BLen( cDay ) )
         ? "Last update:", Bin2I( cYear ), Bin2I( cMonth ), Bin2I( cDay )
         hb_vfClose( hFile )
      ELSE
         ? "Cannot open file"
      ENDIF
   $STATUS$
      R
   $COMPLIANCE$
      C
   $FILES$
      Library is core
   $SEEALSO$
      Bin2L(), Bin2U(), Bin2W(), I2Bin(), L2Bin(), W2Bin(), Word(), U2Bin()
   $END$
 */

/* $DOC$
   $AUTHOR$
      Copyright 2000 Chen Kedem <niki@actcom.co.il>
   $TEMPLATE$
      Function
   $NAME$
      Bin2L()
   $CATEGORY$
      API
   $SUBCATEGORY$
      Conversion
   $ONELINER$
      Convert signed long encoded bytes into Harbour numeric
   $SYNTAX$
      Bin2L( <cBuffer> ) --> nNumber
   $ARGUMENTS$
      <cBuffer> is a character string that contains 32-bit encoded signed
      long integer (least significant byte first). The first four bytes
      are taken into account, the rest if any are ignored.
   $RETURNS$
      Bin2L() return numeric integer (or 0 if <cBuffer> is not a string).
   $DESCRIPTION$
      Bin2L() is one of the low-level binary conversion functions, those
      functions convert between Harbour numeric and a character
      representation of numeric value. Bin2L() take four bytes of encoded
      32-bit signed long 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).

      Bin2L() is the opposite of L2Bin()
   $EXAMPLES$
      // Show number of records in DBF
      #include "fileio.ch"
      LOCAL hFile, cBuffer := Space( 4 )
      IF ( hFile := hb_vfOpen( "test.dbf", FO_READ ) ) != NIL
         hb_vfSeek( hFile, 4 )
         hb_vfRead( hFile, @cBuffer, hb_BLen( cBuffer ) )
         ? "Number of records in file:", Bin2L( cBuffer )
         hb_vfClose( hFile )
      ELSE
         ? "Cannot open file"
      ENDIF
   $STATUS$
      R
   $COMPLIANCE$
      C
   $FILES$
      Library is core
   $SEEALSO$
      Bin2I(), Bin2U(), Bin2W(), I2Bin(), L2Bin(), W2Bin(), Word(), U2Bin()
   $END$
 */

/* $DOC$
   $AUTHOR$
      Copyright 2000 Chen Kedem <niki@actcom.co.il>
   $TEMPLATE$
      Function
   $NAME$
      Bin2W()
   $CATEGORY$
      API
   $SUBCATEGORY$
      Conversion
   $ONELINER$
      Convert unsigned short encoded bytes into Harbour numeric
   $SYNTAX$
      Bin2W( <cBuffer> ) --> nNumber
   $ARGUMENTS$
      <cBuffer> is a character string that contains 16-bit encoded unsigned
      short integer (least significant byte first). The first two bytes
      are taken into account, the rest if any are ignored.
   $RETURNS$
      Bin2W() return numeric integer (or 0 if <cBuffer> is not a string).
   $DESCRIPTION$
      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()
   $EXAMPLES$
      // Show header length of a DBF
      #include "fileio.ch"
      LOCAL hFile, cBuffer := Space( 2 )
      IF ( hFile := hb_vfOpen( "test.dbf", FO_READ ) ) != NIL
         hb_vfSeek( hFile, 8 )
         hb_vfRead( hFile, @cBuffer, hb_BLen( cBuffer ) )
         ? "Length of DBF header in bytes:", Bin2W( cBuffer )
         hb_vfClose( hFile )
      ELSE
         ? "Cannot open file"
      ENDIF
   $STATUS$
      R
   $COMPLIANCE$
      C
   $FILES$
      Library is core
   $SEEALSO$
      Bin2I(), Bin2L(), Bin2U(), I2Bin(), L2Bin(), W2Bin(), Word(), U2Bin()
   $END$
 */

/* $DOC$
   $AUTHOR$
      Copyright 2000 Chen Kedem <niki@actcom.co.il>
   $TEMPLATE$
      Function
   $NAME$
      I2Bin()
   $CATEGORY$
      API
   $SUBCATEGORY$
      Conversion
   $ONELINER$
      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 contains 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"
      LOCAL hFile, cYear, cMonth, cDay
      USE test
      ? "Original update date is:", LUpdate()
      dbCloseArea()
      IF ( hFile := hb_vfOpen( "test.dbf", FO_READWRITE ) ) != NIL
         hb_vfSeek( hFile, 1 )
         cYear  := I2Bin( 68 )
         cMonth := I2Bin(  8 )
         cDay   := I2Bin(  1 )
         hb_vfWrite( hFile, cYear , 1 )  // write only the first byte
         hb_vfWrite( hFile, cMonth, 1 )
         hb_vfWrite( hFile, cDay  , 1 )
         hb_vfClose( hFile )
         USE test
         ? "New update date is:", LUpdate()
         dbCloseArea()
      ELSE
         ? "Cannot open file"
      ENDIF
   $STATUS$
      R
   $COMPLIANCE$
      C
   $FILES$
      Library is core
   $SEEALSO$
      Bin2I(), Bin2L(), Bin2U(), Bin2W(), L2Bin(), W2Bin(), Word(), U2Bin()
   $END$
 */

/* $DOC$
   $AUTHOR$
      Copyright 2000 Chen Kedem <niki@actcom.co.il>
   $TEMPLATE$
      Function
   $NAME$
      L2Bin()
   $CATEGORY$
      API
   $SUBCATEGORY$
      Conversion
   $ONELINER$
      Convert Harbour numeric into signed long encoded bytes
   $SYNTAX$
      L2Bin( <nNumber> ) --> cBuffer
   $ARGUMENTS$
      <nNumber> is a numeric value to convert (decimal digits are ignored).
   $RETURNS$
      L2Bin() return four bytes character string that contains 32-bit
      encoded signed long integer (least significant byte first).
   $DESCRIPTION$
      L2Bin() is one of the low-level binary conversion functions, those
      functions convert between Harbour numeric and a character
      representation of numeric value. L2Bin() take a numeric integer
      value and convert it into four bytes of encoded 32-bit signed long
      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).

      L2Bin() is the opposite of Bin2L()
   $STATUS$
      R
   $COMPLIANCE$
      C
   $FILES$
      Library is core
   $SEEALSO$
      Bin2I(), Bin2L(), Bin2U(), Bin2W(), I2Bin(), W2Bin(), Word(), U2Bin()
   $END$
 */

/* $DOC$
   $TEMPLATE$
      Function
   $NAME$
      Word()
   $CATEGORY$
      API
   $SUBCATEGORY$
      Conversion
   $ONELINER$
      Converts double to integer values.
   $SYNTAX$
      Word( <nDouble> ) --> nInteger
   $ARGUMENTS$
      <nDouble> is a numeric double value.
   $RETURNS$
      Word() return an integer in the range +-32767
   $DESCRIPTION$
      This function converts double values to integers to use
      within the CALL command
   $STATUS$
      R
   $COMPLIANCE$
      The CA-Cl*pper NG states that Word() will only work when used in CALL
      commands parameter list, otherwise it will return NIL, in Harbour
      it will work anywhere.
   $FILES$
      Library is core
   $SEEALSO$
      CALL
   $END$
 */
