Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the value of the expression 13 ^ 25?

  • A.20
  • B.9
  • C.29
  • D.12

Answer: A

Correct answer: 20

XOR keeps a 1 exactly where the two numbers differ:

  13 = 0 1 1 0 1
  25 = 1 1 0 0 1
  --------------
   ^  = 1 0 1 0 0

The first bits differ, so 1; the second are both 1, so 0; the third differ, so 1; the fourth are both 0, so 0; the fifth are both 1, so 0. The result 10100 is \( 16 + 4 = 20 \).

Two properties of XOR are worth carrying away. Applying it twice restores the original - \( (a \oplus b) \oplus b = a \) - which is why it appears in simple ciphers and in the swap-without-a-temporary trick. And \( a \oplus a = 0 \) for any value, which makes XOR the standard way to find the one unpaired element in a list where everything else appears twice.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.