import sys import time import math t1=time.clock() count_add=0 def bin_ORing(b1,b2): global count_add # Pad the components so they are of equal length max_length = max(len(b1), len(b2)) b1, b2 = b1.zfill(max_length), b2.zfill(max_length) ORbinary='' for i in range(0,max_length)[::-1]: if(b1[i] == b2[i] == '0'): ORbinary='0'+ORbinary else: ORbinary='1'+ORbinary count_add=count_add+1 return ORbinary bin_r = open("in7_10.txt",'r') a=bin_r.read() i=a.index(',') p=str(a[0:i]) q=str(a[i+1:len(a)]) ORbin= bin_ORing(p,q) bin_w = file("out_20_7_10.txt",'w') print >>bin_w, ORbin #bin_w.write(str(ORbin)+'\n') bin_w.write('total no of additions is'+" "+str(count_add)+ '\n') t2=time.clock() bin_w.write('time taken is'+" "+ str(t2-t1)+ '\n') bin_w.write('memory taken'+" "+ str(sys.getsizeof(bin_ORing)+sys.getsizeof(ORbin))+'\n') bin_w.close()