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

  1. /*
  2.  * File......: BYT2BIT.PRG
  3.  * Author....: Forest Belt, Computer Diagnostic Services, Inc.
  4.  * Date......: $Date:   15 Aug 1991 23:02:58  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/byt2bit.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/byt2bit.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:02:58   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   14 Jun 1991 19:51:08   GLENN
  20.  * Minor edit to file header
  21.  * 
  22.  *    Rev 1.0   01 Apr 1991 01:00:48   GLENN
  23.  * Nanforum Toolkit
  24.  *
  25.  */
  26.  
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_BYT2BIT()
  31.  *  $CATEGORY$
  32.  *     Conversion
  33.  *  $ONELINER$
  34.  *     Convert byte to string of 1's and 0's
  35.  *  $SYNTAX$
  36.  *     FT_BYT2BIT( <cByte> ) -> cBitPattern
  37.  *  $ARGUMENTS$
  38.  *     <cByte> is the byte to convert.
  39.  *  $RETURNS$
  40.  *     9-character string, consisting of 1's and 0's, representing bits 0
  41.  *     through 7 of parameter byte, with space between bits 3 and 4.  Returns
  42.  *     NIL if parameters are faulty.
  43.  *  $DESCRIPTION$
  44.  *     Can be used to show results of bit manipulation, both before and after.
  45.  *     Binary representation follows right-to-left convention of bit position
  46.  *     numbering, 0 through 7.  Space between high and low nibbles for clarity
  47.  *     and easy comparison to hexadecimal notation.
  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.  *     These three code lines perform a bitwise AND on bytes with values of
  54.  *     CHR(20) and CHR(36), and deliver the result as a string in binary (bit)
  55.  *     format.
  56.  *
  57.  *          ? FT_BYT2BIT(CHR(20))         // byte1: '0001 0100'
  58.  *          ? FT_BYT2BIT(CHR(36))         // byte2: '0010 0100'
  59.  *
  60.  *          ? FT_BYT2BIT(FT_BYTEAND(CHR(20), CHR(36)))
  61.  *                             // result: '0000 0100'
  62.  *
  63.  *     For a demonstration of Clipper bit manipulations, compile and
  64.  *     link the program BITTEST.PRG in the Nanforum Toolkit source code.
  65.  *  $SEEALSO$
  66.  *     FT_BYT2HEX()
  67.  *  $END$
  68.  */
  69.  
  70. FUNCTION FT_BYT2BIT(cByte)
  71.  
  72.   local nCounter, xBitstring
  73.  
  74.   IF valtype(cByte) != "C"
  75.      xBitString := NIL
  76.   ELSE
  77.      xBitString := ""
  78.      FOR nCounter := 7 TO 0 step -1
  79.         xBitString += iif(FT_ISBIT(cByte, nCounter), "1", "0")
  80.      NEXT
  81.   ENDIF
  82.  
  83. RETURN xBitString
  84.  
  85.