Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = 2 in binary 0000 0010
- b = 3 in binary 0000 0011
- while loop (b is not 0):
- data = a&b (& means AND. Keep the bits that exits in BOTH a and b). Data = 0000 0010
- a = a^b (^ means XOR. Copies the bits if it is set in one or the other but not in both) a = 0000 0001
- b = data << 1 (<< 1 means shift the bits left 1 place). b = 0000 0100
- b is not 0 so do the while loop one more time:
- data = a&b. Data is now 0000 0000
- a = a^b. a is now 0000 0101
- b = data << 1. b is now 0000 0000
- b is zero so stop the loop.
- Return a which is 0000 0101 = 5. (Hence 2+3 = 5)!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement