Interview Questions/Coding/Bitwise XOR Tool

Bitwise XOR Tool

Preview mode. Log in to edit, run, submit, and save progress.

Easy

Bitwise XOR Tool

A low-level diagnostics tool compares two integer flags using the bitwise XOR operation. Given two non-negative integers a and b, return the value of a XOR b. In XOR, each binary bit becomes 1 only when the two corresponding bits are different.

Examples

Example 1
Input:
5
3
Output:
6

Explanation: 5 is 101 in binary and 3 is 011. Their XOR is 110, which is 6.

Approach hint

XOR compares bits independently.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp