def num2hexstring(number, size=1, little_endian=False):
    """
    Converts a number to a big endian hexstring of a suitable size, optionally little endian
    :param {number} number
    :param {number} size - The required size in hex chars, eg 2 for Uint8, 4 for Uint16. Defaults to 2.
    :param {boolean} little_endian - Encode the hex in little endian form
    :return {string}
    """
    # if (type(number) != = 'number') throw new Error('num must be numeric')
    # if (num < 0) throw new RangeError('num is unsigned (>= 0)')
    # if (size % 1 !== 0) throw new Error('size must be a whole integer')
    # if (!Number.isSafeInteger(num)) throw new RangeError(`num (${num}) must be a safe integer`)
    size = size * 2
    hexstring = hex(number)[2:]
    if len(hexstring) % size != 0:
        hexstring = ('0' * size + hexstring)[len(hexstring):]
    if little_endian:
        hexstring = reverse_hex(hexstring)
    return hexstring