Tina and her bits assignment
Lesson 14 of 17 in Coddy's Bit Manipulation course.
Challenge
MediumMiss Tina gave her students a positive integer <strong>x</strong>. As an assignment, her students need to find the minimum positive integer <strong>y</strong>, which satisfies the following two conditions:
- x AND y > 0
- x XOR y > 0
Let's take an example,
x = 1: The smallest integer that satisfies above two conditions is 3 as:
1 <strong>AND</strong> 3 = 1 > 01 <strong>XOR</strong> 3 = 2 > 0.
Complete the function MinPositiveY() to find the value of y and return it.
Try it yourself
#include <cmath>
using namespace std;
int MinPositiveY(int x) {
// Write code here
}