def int_to_bytes_big_endian(x: int, n_bytes: int) -> bytearray:
    """Converts integer to bytes in big endian mode"""
    if x >= 256 ** n_bytes:
        raise ValueError("Conversion overflow")
    res = bytearray(n_bytes)
    shift = 0
    for i in range(n_bytes - 1, -1, -1):
        res[i] = (x >> shift) & 0xff
        shift += 8
    return res