def nice_hex(v):
    """
    >>> nice_hex(0x1)
    '$01'
    >>> nice_hex(0x123)
    '$0123'
    """
    if v < 256:
        return '0x%02x' % v
    if v < 65536:
        return '0x%04x' % v
    return '0x%x' % v
