#Chapter-2,Example2_1,pg 2_9
#calculate the input resistance and feedback resistance
#given
Vr=10.
n=4.
Res=0.5#resolution
Rf=10*10**3
#calculations
Rt=Vr/((2**n)*Res)
R=Rt*Rf
#results
print "input resistance (kohm) = ",R/1000.
print "feedback resistance (kohm) = ",Rf/1000.
#Chapter-2,Example2_2,pg 2_11
#calculate the resolution through both methods
#given
n=8
Vofs=2.55#full scale output voltage
#calculations
Res1=2**n
Res2=Vofs/(Res1-1)
#results
print "resolution through method-1 = ",Res1
print "resolution through method-2 (mV) = ",Res2*1000
#Chapter-2,Example2_3,pg 2_12
#calculate the output voltage
#given
n=4.
Vofs=15.
#calculations
Res=Vofs/((2**n)-1)
D=int('0110',base=2)#decimal equivalent
Vo=Res*D
#results
print"output voltage (V) = ",Vo
#Chapter-2,Example2_4,pg 2_12
#calculate the output voltage
#given
Res=20*10**-3
n=8
#calculations
Vofs=Res*((2**n)-1)
D=int('10000000',base=2)
Vo=Res*D
print"output voltage (V) = ",Vo
print"full scale output voltage (V) = ",Vofs
#Chapter-2,Example2_5,pg 2_12
#calculate the output voltage
#given
n=4.
Vofs=5.
#calculations
Res=Vofs/((2**n)-1)
D1=int('1000',base=2)
Vo1=Res*D1
D2=int('1111',base=2)
Vo2=Res*D2
#results
print"output voltage1 (V) = ",round(Vo1,4)
print"output voltage2 (V) = ",Vo2
#Chapter-2,Example2_6,pg 2_13
#calculate the full scale output voltage, percentage resolution
#given
n=12.
Res=8.*10**-3
#calculations
Vofs=Res*((2**n) -1)
perR=Res/Vofs*100.
Vo=Res*int('010101101101',base=2)
#results
print "Full scale output voltage (V) = ",Vofs
print"percentage resolution = ",round(perR,5)
print"output voltage (V) = ",Vo