Menu
CoddyTech

XORty

Lesson 15 of 17 in Coddy's Bit Manipulation course.

challenge icon

Challenge

Easy

In order to celebrate KATY's 5th anniversary, Tengen and Sara decided to play a game.

Tengen gave Sara two integers <strong>a</strong> and <strong>b</strong> and a really important quest.

In order to complete the quest, Sara has to output the smallest possible value of (a⊕x) + (b⊕x) for any given <strong>x</strong>, where ⊕ denotes the bitwise XOR operation.

For example <strong>a = 6</strong> and <strong>b = 12</strong>, then Sara can choose <strong>x = 4</strong> and the value will be (6⊕4) + (12⊕4) = 2+82+8 = 1010. This is the smallest possible value.

Complete the function XORty () to help Sara find the output and return it.

Try it yourself

using namespace std;

int XORty(int a, int b) {
    // Write code here
}

All lessons in Bit Manipulation

Practice on your own: Online C++ compiler