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

  1. /*
  2.  * File......: GTMATH01
  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_BINARY()
  24.  *  $CATEGORY$
  25.  *      Maths
  26.  *  $ONELINER$
  27.  *      Turn a charcter string into a binary number
  28.  *  $SYNTAX$
  29.  *      GT_Binary(<cString>) -> <cBinary>
  30.  *  $ARGUMENTS$
  31.  *      <cString> is any text string of alphanumerics
  32.  *  $RETURNS$
  33.  *      <cBinary> is a string.  Each byte represents one bit.
  34.  *                Eight 'bits' make up the ascii number (in
  35.  *                binary) of the original string.
  36.  *  $DESCRIPTION$
  37.  *      Turns a character string into a binary number, where
  38.  *      every eight bits represents the ascii value of one
  39.  *      byte from the original string, in binary notation.
  40.  *
  41.  *      This can be used for encryption, bit twiddling,
  42.  *      bit stripping etc.
  43.  *  $EXAMPLES$
  44.  *      GT_Binary('AB') -> '0100000101000010'
  45.  *  $SEEALSO$
  46.  *
  47.  *  $INCLUDE$
  48.  *
  49.  *  $END$
  50.  */
  51.  
  52. //   GT_Binary( <cString> )
  53.  
  54. Function GT_Binary(x)
  55.          local y, result := "", z := 8
  56.  
  57.          FOR y := 1 TO Len(x)
  58.              result += SubStr(Replicate('0',z)+;
  59.                        GT_DToB(Asc(SubStr(x,y))),-z)
  60.          Next
  61.  
  62. Return (result)
  63.