## Program to find the binary equivalent of a given series of octal numbers from m to n. ## Start from time import clock import sys def oct_to_decimal(n): dec=0 for i in n: dec= dec*8+ int(i) return dec def dec_to_bin(num): binary_rev='' binary='' n=int(num) while n: rem=n%2 n=n/2 binary_rev=binary_rev + str(rem) binary=binary_rev[::-1] return binary def oct_to_binary(number): memory=0 decimal=oct_to_decimal(number) binary=dec_to_bin(decimal) memory=memory + sys.getsizeof(decimal) + sys.getsizeof(binary) return binary,memory ## End InFile=open("in6_3.txt","r") temp=[] for Row in InFile: temp=Row.split(',') InFile.close() initial= temp[0] final= temp[1] binary_list=[] i= int(initial) start = clock() while i<=int(final): binary_value,memory_space=oct_to_binary(str(i)) binary_list.append(binary_value) if i%10 == 7: i+=3 else: i+=1 time_taken=clock()-start length = len(binary_list) OutFile=open("out_3_sec6_3.txt","w") OutFile=open("out_3_sec6_3.txt","a") OutFile.write(" Output File : \n") for i in range(0,length): if i == length : OutFile.write(binary_list[i]) else: OutFile.write(binary_list[i] + ',') OutFile.write("\n\n Time Taken = " + str(time_taken) + " seconds. ") OutFile.write("\n Memory Space = " + str(memory_space) + " bytes. ") OutFile.write("\n No. of Multiplication = 15. ") OutFile.write("\n No. of Addition = 25. ") OutFile.close() print "\n Output File Generated. "