def int2bytes(a, b):
    """ Converts a given integer value (a) its b-byte representation, in hex format.

    :param a: Value to be converted.
    :type a: int
    :param b: Byte size to be filled.
    :type b: int
    :return: The b-bytes representation of the given value (a) in hex format.
    :rtype: hex str
    """

    m = pow(2, 8*b) - 1
    if a > m:
        raise Exception(str(a) + " is too big to be represented with " + str(b) + " bytes. Maximum value is "
                        + str(m) + ".")

    return ('%0' + str(2 * b) + 'x') % a