print "Representation of the binary number 1101.101 in power of 2"
print "N=(1*2**3)+(1*2**2)+(0*2**1)+(1*2**0)+(1*2**(-1))+(0*2**(-2))+(1*2**(-3))=13.625"
N=(1*2**3)+(1*2**2)+(0*2**1)+(1*2**0)+(1*2**(-1))+(0*2**(-2))+(1*2**(-3))
print "\n The decimal equivalent of binary no 1101.101 is: %.3f"%(N)
## print "representation of the number 567 in power of 8"
print "N=(5*8**2)+(6*8**1)+(7*8**0)=375"
print " Therefore decimal equivalent of 567 is: "
N=(5*8**2)+(6*8**1)+(7*8**0)
print "%.0f"%(N)
print "Representation of the hexadecimalnumber 3FD in power of 16"
print "N=(3*16**2)+(F*16**1)+(D*16**0)=1021"
print ' The Decimal equivalent of the Binary number 3FD is:'#
N=(3*16**2)+(15*16**1)+(13*16**0)
print "%.0f"%(N)
print 'The Decimal equivalent of the number 231.23 with base 4 is: '
x=(2*4**2)+(3*4**1)+(1*4**0)+(2*4**(-1))+(3*4**(-2))
print "%.4f"%(x)
print "decimal from 0 to 9 in radix 5: "
for i in range(0,10):
a=i/5#
b=(i%5)#
print " \t\t\t\t%d=%d%d"%(i,a,b)##conversion from decimal to radix 5
print "Conversion of binary no 111101100 to octal equivalent is :"
a='111101100'#
x=int(a,2)# decimal
y=oct(x)# octal
print "%s"%(y)
print "conversion of octal no 634 to binary equivalent is :"
a='634'
x=int(a,8)#first we convert to decimal
y=bin(x)
print y[2:]
from math import floor
print "conversion of octal no 725.63 to binary equivalent"
a=725.63#
#first we convert the number 725.63(octal)to decimal
x=(7*8**2)+(2*8**1)+(5*8**0)+(6*8**(-1))+(3*8**(-2))#
#then we convert the decimal to binary
z=(x%1)
x=floor(x)##separating the decimal from the integer part
b=0#
c=0#
d=0#
while(x>0) : #taking integer part into a matrix and convert to equivalent binary
y=(x%2)#
b=b+(10**c)*y#
x=x/2#
x=floor(x)#
c=c+1#
for i in range(0,10):##converting the values after the decimal point into binary
z=z*2#
q=floor(z)#
d=d+q/(10**i)#
if z>=1:
z=z-1#
s=b+d#
print "\n The binary equivalent of the given octal number 725.63 is =%.6f"%(s)#
print "hexadecimal equivalent of 1101100010011011 binary is : "
a='1101100010011011'#
x=int(a,2)#
y=hex(x)#
print y[2:]
print "Binary equivalent of 3FD hexadecimal is :"
a='3FD'
y = bin(int(a, 16))[2:]
print '00%s'%y
print "conversion of octal no 615 to its hexadecimal equivalent :",
a='615'#
x=int(a,8)
y=hex(x)
print y[2:]
print "conversion of hexadecimal no 25B to its octal equivalent : ",
a='25B'#
x=int(a,16)
y=oct(x)
print y[2:]
print "conversion of binary no 1101.1 to its decimal equivalent =",
N=(1*2**3)+(1*2**2)+(0*2**1)+(1*2**0)+(1*2**(-1))#
print " %.1f"%(N)
print "conversion of octal no 475.25 to its decimal equivalent ="
N=(4*8**2)+(7*8**1)+(5*8**0)+(2*8**(-1))+(5*8**(-2))#
print " %.5f"%(N)
print "conversion of hexadecimal no 9B2.1A to its decimal equivalent ="
N=(9*16**2)+(11*16**1)+(2*16**0)+(1*16**(-1))+(10*16**(-2))#
print " %.1f"%(N)
print "Conversion of the number 3102.12 \n with base 4 to its decimal equivalent ="
N=(3*4**3)+(1*4**2)+(0*4**1)+(2*4**0)+(1*4**(-1))+(2*4**(-2))#
print " %.3f"%(N)
print "Conversion of the number 614.15 with base 7 to its decimal equivalent ="
N=(6*7**2)+(1*7**1)+(4*7**0)+(1*7**(-1))+(5*7**(-2))#
print " %.4f"%(N)
print "Conversion of decimal number 37 to its binary equivalent =",
a=37#
x=bin(a)#
print "%s"%(x)[2:]
print "conversion of decimal number 214 to its octal equivalent =",
a=214#
x=oct(a)
print x[2:]
print "conversion of decimal number 3509 to its hexadecimal equivalent =",
a=3509#
x=hex(a)
print x[2:]
print "conversion of decimal number 54 base to a number with base 4 =",
a=54
base = 4
def base10toN(num, base):
"""Change ``num'' to given base
Upto base 36 is supported."""
converted_string, modstring = "", ""
currentnum = num
if not 1 < base < 37:
raise ValueError("base must be between 2 and 36")
if not num:
return '0'
while currentnum:
mod = currentnum % base
currentnum = currentnum // base
converted_string = chr(48 + mod + 7*(mod > 10)) + converted_string
return converted_string
print base10toN(a,base)
from math import floor
print "Conversion of decimal number 0.8125 base to its binary equivalent "
a=0.8125
z=(a%1)#
d=0#
for i in range(0,10):##converting the values after the decimal point into binary
z=z*2#
q=floor(z)#
d=d+q/(10**i)#
if z>=1 :
z=z-1#
s=d#
print "\nThe binary equivalent of the given decimal number 0.8125 is = %.4f"%(s)#
from math import floor
print "Conversion of decimal number 0.95 base to its binary equivalent "
a=0.95#
z=(a%1)#
d=0#
for i in range(0,10):##converting the values after the decimal point into binary
z=z*2#
q=floor(z)#
d=d+q/(10**i)#
if z>=1:
z=z-1#
s=d#
print "\n The binary equivalent of the given decimal number 0.95 is = %.7f"%(s)#
print "Conversion of decimal number 0.640625 base to its octal equivalent ="
a=0.640625
z=(a%1)#
d=0#
for i in range(0,10):##converting the values after the decimal point into octal
z=z*8#
q=floor(z)#
d=d+q/(10**i)#
if z>=1:
z=z-q#
s=d#
print "\nThe octal equivalent of the given decimal number 0.640625 is = %.2f"%(s)#
from math import floor
print "Conversion of decimal number 0.1289062 base to its hexadecimal equivalent "
a=0.1289062
z=(a%1)#
d=0#
for i in range(0,10):##converting the values after the decimal point into octal
z=z*16#
q=floor(z)#
d=d+q/(10**i)#
if z>=1 :
z=z-q#
s=d#
print "\nThe hexadecimal equivalent of the given decimal number 0.640625 is = %.3f"%(s)#
from math import floor
print "Conversion of decimal number 24.6 base to its binary equivalent "
a=24.6#
z=(a%1)
x=floor(a)##separating the decimal from the integer part
b=0#
c=0#
d=0#
while(x>0) : #taking integer part into a matrix and convert to equivalent binary
y=(x%2)#
b=b+(10**c)*y#
x=x/2#
x=floor(x)#
c=c+1#
for i in range(0,10):##converting the values after the decimal point into binary
z=z*2#
q=floor(z)#
d=d+q/(10**i)#
if z>=1 :
z=z-1#
s=b+d#
print "\nThe binary equivalent of the given decimal number 24.6 is =%.5f"%(s)#
from math import floor
print "Conversion of decimal number 35.45 to its octal equivalent "
a=35.45#
z=(a)
x=floor(a)##separating the decimal from the integer part
b=0#
c=0#
d=0#
while(x>0): #taking integer part into a matrix and convert to equivalent octal
y=(x%8)#
b=b+(10**c)*y#
x=x/8#
x=floor(x)#
c=c+1#
for i in range(0,10):##converting the values after the decimal point into octal
z=z*8#
q=floor(z)#
d=d+q/(10**i)#
if z>=1 :
z=z-q#
s=b+d#
print "\nThe octal equivalent of the given decimal number 35.45 is =%.5f"%(s)#
from math import floor
print "\n\n Conversion of hexadecimal number 2AC5.D to \n\n"
#conversion into decimal form
N=(2*16**3)+(10*16**2)+(12*16**1)+(5*16**0)+(13*16**(-1))
print " Decimal form = %.4f\n\n"%(N)
#conversion into octal form
#we take the value of the decimal form and convert it to octal form
z=(N%1)
x=floor(N)##separating the decimal from the integer part
b=0#
c=0#
d=0#
while(x>0): #taking integer part into a matrix and convert to equivalent binary
y=(x%8)#
b=b+(10**c)*y#
x=x/8#
x=floor(x)#
c=c+1#
for i in range(0,10):##converting the values after the decimal point intooctal
z=z*8#
q=floor(z)#
d=d+q/(10**i)#
if z>=1:
z=z-q#
s=b+d#
print " Octal form = %.2f\n\n"%(s)#
#conversion into binary form
#we take the value of the decimal form and convert it to octal form
z=(N%1)
x=floor(N)##separating the decimal from the integer part
b=0#
c=0#
d=0#
while(x>0) : #taking integer part into a matrix and convert to equivalent binary
y=(x%2)#
b=b+(10**c)*y#
x=x/2#
x=floor(x)#
c=c+1#
for i in range(0,10):##converting the values after the decimal point into binary
z=z*2#
q=floor(z)#
d=d+q/(10**i)#
if z>=1 :
z=z-1#
s=b+d#
print " Binary form : "
print "\n Integer part 2AC5 = 00%.0f"%(b)
print "\n Decimal part 0.D = %.4f00"%(d)
from math import sqrt
print "\n i)\n Detemination of value of base x \n"
print " (193)_x = (623)_8\n\n"
print " First we convert (623)_8 octal into decimal\n\n"
N=(6*8**2)+(2*8**1)+(3*8**0)
print " (623)_8 = (%.0f)_10\n\n"%(N)
print " Therefore (193)_x = (%.0f)_10\n\n"%(N)
print " (1*x**2)+(9*x**1)+(3*x**0) = %.0f\n\n"%(N)
print " x**2 + 9x + 3 = %.0f\n\n"%(N)
print " x**2 + 9x %.0f = 0\n\n"%(3-N)
a=1#
b=9#
c=-400
x1=(-b+sqrt(b**2-4*a*c))/(2*a)#
x2=(-b-sqrt(b**2-4*a*c))/(2*a)#
print "Therefore x1 = %.0f\n x2 = %.0f"%(x1,x2)
print "\n Negative is not applicable. Therefore x = %.0f"%(x1)
print "\n Hence (193)_%.0f = (623)_8\n\n"%(x1)
print "\n ii)\n Detemination of value of base x \n"
print " (225)_x = (341)_8\n\n"
print " First we convert (341)_8 octal into decimal\n\n"
N=(3*8**2)+(4*8**1)+(1*8**0)
print " (341)_8 = (%.0f)_10\n\n"%(N)
print "Therefore (225)_x = (%.0f)_10\n\n"%(N)
print " (2*x**2)+(2*x**1)+(2*x**0) = %.0f\n\n"%(N)
print " 2x**2 + 2x +5 = %.0f\n\n"%(N)
print " 2x**2 + 2x %.0f= 0\n\n"%(5-N)
a=2#
b=2#
c=-200
x1=(-b+sqrt(b**2-4*a*c))/(2*a)#
x2=(-b-sqrt(b**2-4*a*c))/(2*a)#
print "Therefore x1 = %.0f\n x2 = %.0f"%(x1,x2)
print "\n Negative is not applicable. Therefore x = %.0f"%(x1)
print "\n Hence (225)_%.0f = (341)_8\n\n"%(x1)
print "\n iii)\n Detemination of value of base x \n"
print " (211)_x = (152)_8\n\n"
print " First we convert (152)_8 octal into decimal\n\n"
N=(1*8**2)+(5*8**1)+(2*8**0)
print " (152)_8 = (%.0f)_10\n\n"%(N)
print "Therefore (211)_x = (%.0f)_10\n\n"%(N)
print " (2*x**2)+(1*x**1)+(1*x**0) = %.0f\n\n"%(N)
print " 2x**2 + 1x +1 = %.0f\n\n"%(N)
print " 2x**2 + 1x %.0f = 0\n\n"%(1-N)
a=2#
b=1#
c=-105
x1=(-b+sqrt(b**2-4*a*c))/(2*a)#
x2=(-b-sqrt(b**2-4*a*c))/(2*a)#
print "Therefore x1 = %.0f\n x2 = %.0f"%(x1,x2)
print "\n Negative is not applicable. Therefore x = %.0f"%(x1)
print "\n Hence (211)_%.0f = (152)_8\n\n"%(x1)
print " 1's complement of 1101 = ",
x='1101'
def bitcmp(a):
a= str.replace(a,'0','x')
a = str.replace(a,'1','0')
a= str.replace(a,'x','1')
return a
z = bitcmp(x)
print "%s"%(z)
print "1's complement of 10111001 = ",
x='10111001'
def bitcmp(a):
a= str.replace(a,'0','x')
a = str.replace(a,'1','0')
a= str.replace(a,'x','1')
return a
z = bitcmp(x)
print "%s"%(z)
print " 2's complement 1001 is : ",
x='1001'#
def bitcmp(a):
a= str.replace(a,'0','x')
a = str.replace(a,'1','0')
a= str.replace(a,'x','1')
return a
z = bitcmp(x)
z = int(z,2)+1
z = bin(z)
print "0%s"%(z[2:])
print "2's complement 10100011 is : ",
x='10100011'
z = bitcmp(x)
z = int(z,2)+1
z = bin(z)
print "0%s"%(z[2:])
print "7's complement of(612)_8 is : ",
x='612'
x=int(x,8)
x = bin(x)
x = bitcmp(x)[2:]
x = int(x,2)
x = oct(x)
print x
print "15's complement (A9B)_16 is :",
x='A9B'#
def hex15cmp(n):
nn = int(n,16)
nn = bin(nn)
nn = bitcmp(nn)[2:]
nn = int(nn,2)
nn = hex(nn)
return nn[2:]
y=hex15cmp(x)##hexadecimal to decimal conversion#
print "%s"%y
print "16's complement (A8C)_16 is : ",
x='A8C'#
y=hex15cmp(x)##hexadecimal 15's comp
y = hex(int(y,16)+1)[2:]
print "%s"%(y)
x='1010'#
y='0011'#
#binary to decimal conversion#
x=int(x,2)
y=int(y,2)
z=x+y#
a=bin(z)[2:]#decimal to binary conversion#
print 'the addition of given numbers is: ',
print "%s"%(a)
x=28#
y=15#
# decimal to binary conversion#
z=x+y#
a=bin(z)
print 'the addition of given numbers in binary is: ',
print "%s"%(a)[2:]
print '\n the addition of given numbers in decimal is: ',
print "%.0f"%(z)