home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gtmath08.prg < prev    next >
Text File  |  1993-10-14  |  2KB  |  72 lines

  1. /*
  2.  * File......: GTMATH08
  3.  * Author....: Philip Ide
  4.  * BBS.......: Dark Knight Returns
  5.  * Net/Node..:
  6.  * User Name.: Philip Ide
  7.  * Date......: $Date$
  8.  * Revision..: $Revision$
  9.  * Log file..: $Logfile$
  10.  *
  11.  * This is an original work by Philip Ide and is placed in the
  12.  * public domain.
  13.  *
  14.  * Modification history:
  15.  * ---------------------
  16.  *
  17.  * $Log$
  18.  *
  19.  */
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_INV()
  24.  *  $CATEGORY$
  25.  *      Maths
  26.  *  $ONELINER$
  27.  *      Performs binary inversion on a character string
  28.  *  $SYNTAX$
  29.  *      GT_Inv(<cString>) --> <cString2>
  30.  *  $ARGUMENTS$
  31.  *      <cString> is any character string
  32.  *  $RETURNS$
  33.  *      <cString2> is a binary inverted version of <cString>
  34.  *  $DESCRIPTION$
  35.  *      This function takes a character string, turns it into a stream
  36.  *      of binary digits (each eight 'bits' represents one character
  37.  *      from the input string, and is it's ASCII value), then inverts
  38.  *      the 'bits', and finaly turns the stream back into a string of
  39.  *      ASCII characters.
  40.  *
  41.  *      Passing the inverted string back to the function will cause it
  42.  *      to revert to it's initial state.
  43.  *  $EXAMPLES$
  44.  *      ? GT_Inv('101010')           // '010101'
  45.  *
  46.  *      ? GT_Inv('SAM')              // '½╜¡'
  47.  *
  48.  *      ? GT_Inv(GT_Inv('SAM'))      // 'SAM'
  49.  *  $SEEALSO$
  50.  *      GT_BINARY() GT_BTOD() GT_DTOB()
  51.  *  $INCLUDE$
  52.  *
  53.  *  $END$
  54.  */
  55.  
  56. FUNCTION GT_Inv(cString)
  57. LOCAL xcounter, ycounter, zcounter
  58. LOCAL tempString, bit, result := "", res := ""
  59. zcounter := 8
  60. cString := GT_Binary(cString)
  61. FOR xcounter := 1 To len(cString)/8
  62.    tempString := SubStr(cString,(xcounter*8)-7,8)
  63.    res := ""
  64.    FOR ycounter := 1 TO zcounter
  65.       bit := IF( SubStr(tempString,ycounter,1) = '1', '0',;
  66.                  '1' )
  67.       res += bit
  68.    NEXT
  69.    result += Chr(GT_BToD(res))
  70. NEXT
  71. Return (result)
  72.