home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / BYTEOR.PRG < prev    next >
Text File  |  1991-08-16  |  3KB  |  83 lines

  1. /*
  2.  * File......: BYTEOR.PRG
  3.  * Author....: Forest Belt, Computer Diagnostic Services, Inc.
  4.  * Date......: $Date:   15 Aug 1991 23:03:06  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/byteor.prv  $
  7.  * 
  8.  * This is an original work by Forest Belt and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/byteor.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:03:06   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   14 Jun 1991 19:51:16   GLENN
  20.  * Minor edit to file header
  21.  * 
  22.  *    Rev 1.0   01 Apr 1991 01:00:56   GLENN
  23.  * Nanforum Toolkit
  24.  *
  25.  */
  26.  
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_BYTEOR()
  31.  *  $CATEGORY$
  32.  *     String
  33.  *  $ONELINER$
  34.  *     Perform bit-wise OR on two ASCII characters (bytes)
  35.  *  $SYNTAX$
  36.  *     FT_BYTEOR( <cByte1>, <cByte2> ) -> cNewByte
  37.  *  $ARGUMENTS$
  38.  *     <cByte1> and <cByte2> are characters from CHR(0) TO CHR(255).
  39.  *     May be passed in CHR() form, as character literals, or as
  40.  *     expressions evaluating to CHR() values.
  41.  *  $RETURNS$
  42.  *     Returns resulting byte, in CHR() form.  If parameters are faulty,
  43.  *     returns NIL.
  44.  *  $DESCRIPTION$
  45.  *     Can be used for bit-wise byte manipulation.  In effect, this is a
  46.  *     bit-by-bit OR operation.  Equivalent to OR assembler instruction.
  47.  *
  48.  *     This function is presented to illustrate that bit-wise operations
  49.  *     are possible with Clipper code.  For greater speed, write .C or
  50.  *     .ASM versions and use the Clipper Extend system.
  51.  *  $EXAMPLES$
  52.  *          This code performs a bit-wise OR on two bytes represented
  53.  *          by CHR(20) and CHR(10):
  54.  *
  55.  *          cNewByte := FT_BYTEOR( CHR(20), CHR(10) )
  56.  *          ? ASC( cNewByte )  // result: 30
  57.  *          ? cNewByte         // result: non-printable character
  58.  *
  59.  *     For a demonstration of Clipper bit manipulations, compile and
  60.  *     link the program BITTEST.PRG in the Nanforum Toolkit source code.
  61.  *  $SEEALSO$
  62.  *     FT_BYTEXOR() FT_BYTENOT() FT_BYTENEG() FT_BYTEAND()
  63.  *  $END$
  64.  */
  65.  
  66. FUNCTION FT_BYTEOR(cByte1, cByte2)
  67.  
  68.   LOCAL nCounter, cNewByte
  69.  
  70.   IF valtype(cByte1) != "C" .or. valtype(cByte2) != "C" // parameter check
  71.      cNewByte := NIL
  72.   ELSE
  73.      cNewByte := chr(0)
  74.      for nCounter := 0 to 7           // test each bit position
  75.         if FT_ISBIT(cByte1, nCounter) .or. FT_ISBIT(cByte2, nCounter)
  76.            cNewByte := FT_BITSET(cNewByte, nCounter)
  77.         endif
  78.      next
  79.   ENDIF
  80.  
  81. RETURN cNewByte
  82.  
  83.