code: def _converttobitstring(cls, bs, offset=0, cache={}):
          
          if isinstance(bs, Bits):
              return bs
          try:
              return cache[(bs, offset)]
          except KeyError:
              if isinstance(bs, basestring):
                  b = cls()
                  try:
                      _, tokens = tokenparser(bs)
                  except ValueError as e:
                      raise CreationError(*e.args)
                  if tokens:
                      b._append(Bits._init_with_token(*tokens[0]))
                      b._datastore = offsetcopy(b._datastore, offset)
                      for token in tokens[1:]:
                          b._append(Bits._init_with_token(*token))
                  assert b._assertsanity()
                  assert b.len == 0 or b._offset == offset
                  if len(cache) < CACHE_SIZE:
                      cache[(bs, offset)] = b
                  return b
          except TypeError:
              # Unhashable type
              pass
          return cls(bs)
docs: Convert bs to a bitstring and return it.
  
          offset gives the suggested bit offset of first significant
          bit, to optimise append etc.