def base256_encode(n, minwidth=0):  # int/long to byte array
    """
    Encode the input with base256.

    Args:
        n (int): input value.
        minwidth: minimum return value length.

    Raises:
        ValueError: if a negative number is provided.

    Returns:
        bytearray:
    """
    if n > 0:
        arr = []
        while n:
            n, rem = divmod(n, 256)
            arr.append(rem)
        b = bytearray(reversed(arr))
    elif n == 0:
        b = bytearray(b'\x00')
    else:
        raise ValueError("Negative numbers not supported")

    if minwidth > 0 and len(b) < minwidth:  # zero padding needed?
        padding = (minwidth - len(b)) * b'\x00'
        b = bytearray(padding) + b
    b.reverse()

    return b
def base256_encode ( n , minwidth = 0 ) : if n > 0 : arr = [ ] while n : n , rem = divmod ( n , 256 ) arr . append ( rem ) b = bytearray ( reversed ( arr ) ) elif n == 0 : b = bytearray ( b'\x00' ) else : raise ValueError ( "Negative numbers not supported" ) if minwidth > 0 and len ( b ) < minwidth : padding = ( minwidth - len ( b ) ) * b'\x00' b = bytearray ( padding ) + b b . reverse ( ) return b
Encode the input with base256.

    Args:
        n (int): input value.
        minwidth: minimum return value length.

    Raises:
        ValueError: if a negative number is provided.

    Returns:
        bytearray: