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

  1. /*
  2.  * File......: BITCLR.PRG
  3.  * Author....: Forest Belt, Computer Diagnostic Services, Inc.
  4.  * Date......: $Date:   15 Aug 1991 23:02:50  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/bitclr.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/bitclr.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:02:50   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   14 Jun 1991 19:50:58   GLENN
  20.  * Minor edit to file header
  21.  * 
  22.  *    Rev 1.0   01 Apr 1991 01:00:40   GLENN
  23.  * Nanforum Toolkit
  24.  *
  25.  */
  26.  
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_BITCLR()
  31.  *  $CATEGORY$
  32.  *     String
  33.  *  $ONELINER$
  34.  *     Clear (reset) selected bit in a byte
  35.  *  $SYNTAX$
  36.  *     FT_BITCLR( <cByte>, <nBitPos> ) -> cByte
  37.  *  $ARGUMENTS$
  38.  *     <cByte> is a character from CHR(0) to CHR(255).
  39.  *
  40.  *     <nBitPos> is a number from 0 to 7 conforming to standard
  41.  *     right-to-left bit numbering convention and representing the
  42.  *     position of the bit within the byte.
  43.  *  $RETURNS$
  44.  *     Returns new byte, with designated bit cleared (reset).
  45.  *     If parameters are faulty, returns NIL.
  46.  *  $DESCRIPTION$
  47.  *     In effect, ANDs argument byte with a byte that has all bits set except
  48.  *     the target bit.  If bit is already clear (0), it remains clear.
  49.  *     Note: Calls FT_ISBIT() which is also in this Library.
  50.  *
  51.  *     This function is presented to illustrate that bit-wise operations
  52.  *     are possible with Clipper code.  For greater speed, write .C or
  53.  *     .ASM versions and use the Clipper Extend system.
  54.  *  $EXAMPLES$
  55.  *     This code would clear bit 4 in a byte represented by CHR(115):
  56.  *
  57.  *       cNewByte := FT_BITCLR( CHR(115), 4 )
  58.  *       ? ASC( cNewbyte )         // result: 99
  59.  *       ? cNewByte                // result: 'c'
  60.  *
  61.  *     This code would clear bit 5 in the byte represented by letter 'A':
  62.  *
  63.  *       FT_BITCLR( 'A', 5 )       // result: 'A', since
  64.  *                                 // bit 5 already clear
  65.  *
  66.  *     For a demonstration of Clipper bit manipulations, compile and
  67.  *     link the program BITTEST.PRG in the Nanforum Toolkit source code.
  68.  *  $SEEALSO$
  69.  *     FT_BITSET() FT_ISBIT()
  70.  *  $END$
  71.  */
  72.  
  73. FUNCTION FT_BITCLR(cInbyte, nBitpos)
  74.  
  75.   LOCAL cByte
  76.  
  77.   IF valtype(cInbyte) != "C" .or. valtype(nBitpos) != "N"  // parameter check
  78.      cByte := NIL
  79.   ELSE
  80.      IF (nBitPos > 7) .or. (nBitPos < 0) .or. (nBitPos != int(nBitPos))
  81.         cByte := NIL
  82.      ELSE
  83.         cByte := iif( .not. FT_ISBIT(cInByte, nBitpos), cInByte, ;
  84.                              chr(asc(cInByte) - (2 ^ nBitpos)))
  85.      ENDIF
  86.   ENDIF
  87.  
  88. RETURN cByte
  89.  
  90.