def rev_bits(x: int, width: int = 0) -> int:
    """Return the given integer but with the bits reversed.

    Params:
        x     - integer to reverse
        width - width of the integer (in bits)

    Returns:
        The reversed integer.
    """
    if not width:
        width = x.bit_length()

    rev = 0

    for i in range(width):
        bit = x & (1 << i)
        if bit: rev |= (1 << (width - i - 1))

    return rev