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

  1. /*
  2.  * File......: BYTENEG.PRG
  3.  * Author....: Forest Belt, Computer Diagnostic Services, Inc.
  4.  * Date......: $Date:   15 Aug 1991 23:03:04  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/byteneg.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/byteneg.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:03:04   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   14 Jun 1991 19:51:14   GLENN
  20.  * Minor edit to file header
  21.  * 
  22.  *    Rev 1.0   01 Apr 1991 01:00:52   GLENN
  23.  * Nanforum Toolkit
  24.  *
  25.  */
  26.  
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_BYTENEG()
  31.  *  $CATEGORY$
  32.  *     String
  33.  *  $ONELINER$
  34.  *     Perform bit-wise negation on an ASCII character
  35.  *  $SYNTAX$
  36.  *     FT_BYTENEG( <cByte> ) -> cNewByte
  37.  *  $ARGUMENTS$
  38.  *     <cByte> is a character from CHR(0) to CHR(255).
  39.  *     May be passed in CHR() form, as character literal, or
  40.  *     as expression evaluating to CHR() value.
  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 NEG (two's complement) operation.  Equivalent to NEG
  47.  *     assembler instruction.
  48.  *
  49.  *     This function is presented to illustrate that bit-wise operations
  50.  *     are possible with Clipper code.  For greater speed, write .C or
  51.  *     .ASM versions and use the Clipper Extend system.
  52.  *  $EXAMPLES$
  53.  *     This code performs a bit-wise NEG on byte represented by CHR(32):
  54.  *
  55.  *          cNewByte := FT_BYTENOT(CHR(32))
  56.  *          ? asc(cNewByte)                  // result: 224
  57.  *
  58.  *     For a demonstration of Clipper bit manipulations, compile and
  59.  *     link the program BITTEST.PRG in the Nanforum Toolkit source code.
  60.  *  $SEEALSO$
  61.  *     FT_BYTEOR() FT_BYTEXOR() FT_BYTENOT() FT_BYTEAND()
  62.  *  $END$
  63.  */
  64.  
  65.  
  66. FUNCTION FT_BYTENEG(cByte)
  67. RETURN   iif(valtype(cByte) != "C", NIL, chr((256 - asc(cByte)) % 256))
  68.  
  69.