Discussion
What is the value of the expression 13 ^ 25?
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 0The 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.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development