Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Decimal Numbers have to be supplied.
- def x0r(n32,n16):
- bn32=bin(n32)[2:]
- bn16=bin(n16)[2:]
- while (len(bn32)<32):
- bn32='0'+bn32
- while (len(bn16)<16):
- bn16='0'+bn16
- bn32r=bn32[16:]
- print bn32
- bn32=bn32[:16]
- print
- print bn32
- print bn16
- ans=''
- i=0
- while i<16:
- ans+=str(int(bn32[i])^int(bn16[i]))
- i+=1
- ans+=bn32r
- print "Binary is : ",ans
- return dec(ans)
- # Number Supplied as BinaryString to dec
- def dec(bn):
- i=0
- val=0
- while i<len(bn):
- if bn[i]=='1':
- val+=(2**(len(bn[i:])-1))
- i+=1
- print "Decimal Equivalent is :",str(val)
- return val
- #print x0r(1060286764,52)
- dec('00011111101011010101100010010110')
Add Comment
Please, Sign In to add comment