import math


def zhex(v):
    """Returns number as zero-padded hex, e.g. "0x0C" for 12 and "0x0100" for 256."""
    if not v: return "0x00"
    sign, v = ("-" if v < 0 else ""), abs(v)
    return "%s0x%0*X" % (sign, 2 * int(1 + math.log(v) / math.log(2) // 8), v)