docs: def count(self, value):
          """Return count of total number of either zero or one bits.
  
          value -- If True then bits set to 1 are counted, otherwise bits set
                   to 0 are counted.
  
          >>> Bits('0xef').count(1)
          7
  
          """
          if not self.len:
              return 0
          # count the number of 1s (from which it's easy to work out the 0s).
          # Don't count the final byte yet.
          count = sum(BIT_COUNT[self._datastore.getbyte(i)] for i in xrange(self._datastore.bytelength - 1))
          # adjust for bits at start that aren't part of the bitstring
          if self._offset:
              count -= BIT_COUNT[self._datastore.getbyte(0) >> (8 - self._offset)]
          # and count the last 1 - 8 bits at the end.
          endbits = self._datastore.bytelength * 8 - (self._offset + self.len)
          count += BIT_COUNT[self._datastore.getbyte(self._datastore.bytelength - 1) >> endbits]
          return count if value else self.len - count