def binexp(x: int, n: int) -> int:
    """Binary exponentiation

    Parameters:
    x (int): Base
    n (int): Exponent (power)

    Returns:
    int: Result
    """

    res = 1

    while n > 0:
        if n & 1 > 0:
            res *= x

        x *= x
        n >>= 1

    return res