import math


def number_to_hex(number, width):
    """
    Return the hex string representation of the given number.

    :param number: Number to convert
    :type number: int

    :param width: Width of the result in bits
    :type width: int

    :return: The number as a hex string
    :rtype: str

    :raise OverflowError: If the number does not fit into the given width.

    >>> number_to_hex(0xC0FFEE, 24)
    'C0FFEE'
    >>> number_to_hex(0xC0FFEE, 30)
    '00C0FFEE'
    >>> number_to_hex(0xC0FFEE, 23)
    Traceback (most recent call last):
        ...
    OverflowError: 12648430 does not fit into 23 bits

    """
    if number >> width != 0:
        raise OverflowError(
            '{0} does not fit into {1} bits'.format(number, width)
        )
    return '{0:0{1}X}'.format(number, int(math.ceil(width / 4.0)))