def modulate(v):
    """Modulates a value

    >>> modulate((1, (81740, None)))
    '110110000111011111100001001111110100110000'
    >>> modulate(0)
    '010'
    >>> modulate(1)
    '01100001'
    >>> modulate(-1)
    '10100001'
    >>> modulate(81740)
    '0111111000010011111101001100'
    """
    if v is None:
        return "00"
    if type(v) is tuple:
        if len(v) != 2:
            raise ValueError()
        return "11" + modulate(v[0]) + modulate(v[1])
    ret = ""
    if v >= 0:
        ret += "01"
    else:
        ret += "10"
        v *= -1

    bits = ""
    while v:
        bits += str(v % 2)
        v //= 2
    bits = bits[::-1]
    bitlen = 0
    while bitlen * 4 < len(bits):
        bitlen += 1
    ret += '1' * bitlen + '0'
    ret += '0' * (bitlen * 4 - len(bits)) + bits
    return ret