def writeBew(value, length):
    """
    Write int as big endian formatted bytes, (asserts length in [1,2,4])
    Difficult to print the result in doctest, so I do a simple roundabout test.
    >>> readBew(writeBew(25057, 2))
    25057
    >>> readBew(writeBew(1642193635, 4))
    1642193635
    >>> readBew(writeBew(16, 3))
    Traceback (most recent call last):
        ...
    ValueError: words must be one of 1,2 or 4
    """
    if not length in [1, 2, 4]:
        raise ValueError('words must be one of 1,2 or 4')
    return value.to_bytes(length, byteorder='big', signed=False)
