def _val_to_byte_list(number, num_bytes, big_endian=True):
    """
    Converts an integer into a big/little-endian multi-byte representation.
    Similar to int.to_bytes() in the standard lib but returns a list of integers
    between 0 and 255 (which allows for bitwise arithmetic) instead of a bytearray.
    """
    if number > (2**(8*num_bytes))-1:
        raise ValueError("Unsigned integer %d does not fit into %d bytes!" % (number, num_bytes))
    byte_list = []
    for b in range(num_bytes):
        val = (number >> (8*b)) & 0xff
        if big_endian:
            byte_list.insert(0, val)
        else:
            byte_list.append(val)
    return byte_list