from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer, IBMQ
import qiskit_tools as qt
import numpy as np
import matplotlib.pyplot as plt
import matplotlib

in_digit = np.pi
print(in_digit)

n = 20

nint = qt.get_nint(in_digit)
print(nint)

in_binary = qt.my_binary_repr(in_digit, n, nint=nint, phase=False)
print(in_binary)

out_digit = qt.bin_to_dec(in_binary, nint=nint, phase=False)
print(out_digit)

n-nint

in_digit = -3.25
print(in_digit)

nint = qt.get_nint(in_digit)
print(nint)

npres = qt.get_npres(in_digit)
print(npres)

n = npres + nint + 1

in_binary = qt.my_binary_repr(in_digit, n, nint=nint, phase=True)
print(in_binary)

out_digit = qt.bin_to_dec(in_binary, nint=nint, phase=True)
print(out_digit)

sm_binary = qt.my_binary_repr(in_digit, n, nint=nint, phase=True, signmag=True)
print(sm_binary, qt.bin_to_dec(sm_binary, nint=nint, phase=True, signmag=True))

qreg = QuantumRegister(n, 'bit')
circ = QuantumCircuit(qreg)

circ = qt.input_bits_to_qubits(in_binary, circ, qreg)

circ.draw(output="latex")