def rev_bit_str(n: int, bitlen: int) -> int:
    """
    Reverses the bitstring of length bitlen of a number n and returns the
    bitreverses integer. I.e. rev_bits(3, 4) => "0011" => "1100" => 12
    """
    bits = bin(n)[2:]  # Truncate first 2 characters to avoid '0b'
    start_pow = bitlen - len(bits)
    return sum([2 ** (idx + start_pow) if bit == '1' else 0
                for idx, bit in enumerate(bits)])