import struct


def Bits2Str(v):
  """Converts a vector of bits to a string."""

  def Bits2Char(byte):
    return struct.pack('>B', int(''.join([str(b) for b in byte]), 2))

  return b''.join([Bits2Char(v[8 * i:8 * i + 8]) for i in range(len(v) // 8)])