Advertisement
Vladislava

Untitled

Aug 3rd, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. firstbin = 0b1110
  2. secondbin = 0b101
  3. strfirstbin = str(bin(firstbin))
  4. strsecondbin = str(bin(secondbin))
  5. fbin2 = strfirstbin[2::]
  6. sbin2 = strsecondbin[2::]
  7. lenf = len(fbin2)
  8. lens = len(sbin2)
  9. result = []
  10.  
  11. if lenf == lens:
  12.     for i in fbin2:
  13.         if i == "1":
  14.             for d in sbin2:
  15.                 if i == d:
  16.                     result.append("1")
  17.                 else:
  18.                     result.append("0")
  19.         else:
  20.             result.append("0")
  21. else:
  22.     if lenf > lens:
  23.         substr = lenf - lens
  24.         fbin3 = fbin2[int(substr)::]
  25.         for i in fbin3:
  26.             if i == "1":
  27.                 for d in sbin2:
  28.                     if d == i:
  29.                         result.append("1")
  30.                     else:
  31.                         result.append("0")
  32.             else:
  33.                  result.append("0")
  34.                        
  35.     elif lens > lenf:
  36.         substr = lens - lenf
  37.         sbin3 = sbin2[int(substr)::]
  38.         for i in fbin2:
  39.             if i == "1":
  40.                 for d in sbin3:
  41.                     if d == i:
  42.                         result.append("1")
  43.                     else:
  44.                         result.append("0")
  45.             else:
  46.                 result.append("0")
  47. print "".join(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement