def int_to_c(k, x_width):
    """
    Takes an integer and a width and returns a complex number.
    """
    ik = k >> x_width
    qk = k % pow(2, x_width)
    maxint = pow(2, x_width)-1
    i = ik * 2.0 / maxint
    q = qk * 2.0 / maxint
    if i > 1:
        i -= 2
    if q > 1:
        q -= 2
    return i + (0+1j)*q