man(1) Manual page archive


     BITS(3+)                                                 BITS(3+)

     NAME
          bits - variable length bit strings

     SYNOPSIS
          #include <Bits.h>

          typedef unsigned long Bits_chunk;

          struct Bits {
               Bits() { }
               Bits(Bits_chunk, unsigned = 1);
               Bits(const Bits&)
               ~Bits();
               Bits& operator= (const Bits&);     // also = &= |= ^=
               Bits& operator<<= (int);      // also >>=
               int operator[] (unsigned);
               operator Bits_chunk();
               unsigned size();
               unsigned size(unsigned);
               Bits& compl();
               Bits& concat(const Bits&);
               Bits& set(unsigned, unsigned long = 1);
               Bits& reset(unsigned);
               Bits& compl(unsigned);
               unsigned count();
               unsigned signif();
               unsigned trim();
          };

          Bits operator~ (const Bits&);
          Bits operator& (const Bits&, const Bits&); // also | ^
          Bits operator<< (const Bits&, int);           // also >>
          int operator< (const Bits&, const Bits&);     // also > <= >= == !=

     DESCRIPTION
          A Bits object contains a variable-length bit string.  The
          bits of a Bits object b are numbered from 0 through
          b.size()-1, with the rightmost bit numbered 0.

          Bits_chunk is the largest unsigned integral type acceptable
          for conversion to and from Bits, unsigned long in this
          implementation.

        Constructors
          Bits()      An empty bit string.

          Bits(n)     The bits are copied from the binary representa-
                      tion of n with the ones-digit of n becoming bit
                      0.  Leading zero-bits are removed, except that
                      Bits(0) is a one-bit string.

     BITS(3+)                                                 BITS(3+)

          Bits(n,m)   The same, but padded with leading zeros to size
                      m if necessary.

        Operators
          Bit strings have value semantics; assigning a Bits object or
          passing it to or returning it from a function creates a copy
          of its value.  The meanings of operators are mostly pre-
          dictable from C.

          Under binary and comparison operators, the shorter operand
          is considered to be padded on the left with zeros to the
          length of the longer.  If, after padding, two strings of
          different length compare equal, the shorter is deemed the
          smaller.

          Negative shift amounts reverse the sense of shift operators.

          Under conversion (or assignment) to a Bits_chunk, a Bits is
          interpreted as an unsigned integer.  If it has a value small
          enough to fit, that value is assigned.  Otherwise, a non-
          zero value is assigned.  Thus a Bits is considered `true' in
          an if test if it contains any one-bit, `false' otherwise.

          a[s]        Bit number s of a; 0 if s is out of bounds.

        Other functions
          a.size(s)   Set the size of a to s by truncating or padding
                      with zeros on the left as necessary.  Return the
                      new size.

          a.compl()   Complement the bits of a. Return a.

          a.set(s)
          a.reset(s)
          a.compl(s)  Set, reset, or complement bit s of a. No effect
                      if a.size()<=s.  Return a.

          a.set(s,n)  If n is 0, reset bit s of a, otherwise set bit
                      s. Equivalent to n? a.set(s): a.reset(s).

          a.count()   Return the number of one-bits in a.

          a.signif()  Return the number of significant bits in a: one
                      more than the number of the leftmost one-bit, or
                      zero if there is no one-bit.

          a.trim()    Discard high-order zero-bits.  Equivalent to
                      a.size(a.signif()).

          a.concat(b) Concatenate the value of b to the right (low-
                      order) end of a. Return a.

     BITS(3+)                                                 BITS(3+)

          concat(a,b) Return a newly created concatenated object.

     DIAGNOSTICS
          An operation that runs out of memory sets the length of the
          affected Bits to zero.

     BUGS
          Too bad C++ can't support a[s] = n.
          Things would be more consistent if Bits(0).size() were zero.