def get_bits(num, gen):
    """ Get "num" bits from gen """
    out = 0
    for i in range(num):
        out <<= 1
        val = gen.next()
        if val != []:
            out += val & 0x01
        else:
            return []

    return out