Advertisement
trodland

Untitled

Apr 8th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. a = 2 in binary 0000 0010
  2. b = 3 in binary 0000 0011
  3.  
  4. while loop (b is not 0):
  5. data = a&b (& means AND. Keep the bits that exits in BOTH a and b). Data = 0000 0010
  6. a = a^b (^ means XOR. Copies the bits if it is set in one or the other but not in both) a = 0000 0001
  7. b = data << 1 (<< 1 means shift the bits left 1 place). b = 0000 0100
  8.  
  9. b is not 0 so do the while loop one more time:
  10. data = a&b. Data is now 0000 0000
  11. a = a^b. a is now 0000 0101
  12. b = data << 1. b is now 0000 0000
  13.  
  14. b is zero so stop the loop.
  15.  
  16. Return a which is 0000 0101 = 5. (Hence 2+3 = 5)!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement