from time import clock import sys def octal_to_decimal(n): m=n[::-1] base=1 sum=0 global addcount global mulcount for i in m: sum=sum+base*int(i) addcount+=1 mulcount+=1 base=base*8 return sum,addcount,mulcount def hex(w,w1): f1=[] while w<=w1: x=w x1='' while x >0: x2=x % 16 if x2 == 10 : x1=x1+'A' elif x2 == 11 : x1= x1+'B' elif x2 == 12 : x1= x1+'C' elif x2 == 13 : x1=x1+'D' elif x2 == 14 : x1=x1+'E' elif x2 == 15 : x1=x1+'F' else : x1=x1+str(x2) x=x/16 x1=x1[::-1] f1.append(x1) w=w+1 return f1 start=clock() input=open("c:\inputs\in5_6.txt","r") output=open("out_3_sec5_6.txt","w") for row in input: list=row.split(",") m=list[0] n=list[1] addcount=0 mulcount=0 k=[] mdec,add1,mul1=octal_to_decimal(m) ndec,add2,mul2=octal_to_decimal(str(int(n))) mul=mul1+mul2 add=add1+add2 k=hex(mdec,ndec) print k el=clock()-start mem=sys.getsizeof(mdec)+sys.getsizeof(ndec)+sys.getsizeof(mul)+sys.getsizeof(add)+sys.getsizeof(list)+sys.getsizeof(el) output.write(("hexa's ")+str(k)+"\nmultiplication "+str(mul)+"\n addition "+str(add)+"\nmemory "+str(mem)) print mem input.close() output.close()