Formats a hexadeciaml field.

def format_hexadecimal_field(spec, prec, number, locale):
    """Formats a hexadeciaml field."""
    if number < 0:
        # Take two's complement.
        number &= (1 << (8 * int(math.log(-number, 1 << 8) + 1))) - 1
    format_ = u'0%d%s' % (int(prec or 0), spec)
    return format(number, format_)