code: def tobytes(self):
          
          d = offsetcopy(self._datastore, 0).rawbytes
          # Need to ensure that unused bits at end are set to zero
          unusedbits = 8 - self.len % 8
          if unusedbits != 8:
              d[-1] &= (0xff << unusedbits)
          return bytes(d)
docs: Return the bitstring as bytes, padding with zero bits if needed.
  
          Up to seven zero bits will be added at the end to byte align.