home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / basic / QBBITS.ZIP / BITSTUFF.DOC < prev    next >
Encoding:
Text File  |  1989-08-12  |  2.4 KB  |  64 lines

  1.      Aug 12, 1989
  2.  
  3.      This ARC contains the MASM source, .OBJ and .QLB for a set of bit-level
  4. manipulation routines to use with QB/BC.  If you make modifications, you'll
  5. need MASM 5.1 to reassemble.
  6.  
  7.      Routines are included to set, clear, toggle and examine the state of any
  8. single bit in a 16-bit word.  These allows the programmer to maintain 16
  9. separate flags in a single integer, with quick access to any flag.  If you
  10. use global flags, you'll find these fast and convenient.
  11.  
  12.      Also included are routines to convert between numeric values and binary
  13. strings, for example "10011".
  14.  
  15.      Uploaded to MSSYS for the free use of its members.  Not copyrighted.
  16. If you find these useful, drop me a note.  Likewise, if you encounter any
  17. problems or have comments or questions, please let me know at once:
  18.  
  19.      Jim Mack [76630,2012] via MSSYS
  20.  
  21.      Detailed descriptions follow.  Also see the MASM source and the QB test
  22. program for more information.
  23.  
  24. ═══════════════
  25.  
  26.      DECLARE SUB SetBit (bitnumber%, word%)
  27.      DECLARE SUB ClearBit (bitnumber%, word%)
  28.      DECLARE SUB ToggleBit (bitnumber%, word%)
  29.  
  30.      WORD% is the 16-bit quantity where the selected bit resides.
  31.      Set, Clear and ToggleBit alter WORD% directly.
  32.  
  33.      BITNUMBER% ranges from 1 to 16.  If you exceed 16, what happens
  34.      depends on what processor you're using.  Zero affects no bits.
  35.  
  36. ═══════════════
  37.  
  38.      DECLARE FUNCTION BitState% (bitnumber%, word%)
  39.  
  40.      Returns a logical "true" (-1) if the selected bit is set in WORD%, or a
  41.      logical "false" (0) otherwise.  WORD% is not altered.
  42.  
  43. ═══════════════
  44.  
  45.      DECLARE FUNCTION BitStr$ (word%)
  46.  
  47.      Returns a 16-character string of ASCII ones and zeros with a "1" in
  48.      each position where a bit is set in WORD%.  For example, passing 12
  49.      returns the string "0000000000001100".
  50.  
  51. ═══════════════
  52.  
  53.      DECLARE FUNCTION BitVal& (binar$)
  54.  
  55.      Returns a long integer quantity reflecting the value of a passed string
  56.      of ASCII ones and zeroes.  BINAR$ can contain any number of digits, but
  57.      only the first 16 are evaluated.  If it contains fewer than 16 digits,
  58.      they are considered as the less significant bits (i.e. "01" is taken to
  59.      mean "0000000000000001" and evaluates to 1).  Strings which contain
  60.      *any* other character in the first 16 positions are rejected, and a
  61.      value of zero returned.
  62.  
  63. ═══════════════
  64.