Complete the code to check if a number is even using bitwise AND.
bool isEven(int num) {
return (num & [1]) == 0;
}The least significant bit (LSB) of an even number is 0. Using bitwise AND with 1 checks this bit.
Complete the code to print "Even" if number is even, else "Odd".
if ((num & [1]) == 0) { std::cout << "Even"; } else { std::cout << "Odd"; }
Bitwise AND with 1 checks the last bit to determine even or odd.
Fix the error in the function that returns true if number is odd using bits.
bool isOdd(int num) {
return (num & [1]) == 1;
}To check if a number is odd, bitwise AND with 1 should equal 1.
Fill both blanks to create a function that returns "Even" or "Odd" using bits.
std::string checkEvenOdd(int num) {
if ((num [1] [2]) == 0) {
return "Even";
} else {
return "Odd";
}
}Use bitwise AND (&) with 1 to check the least significant bit.
Fill all three blanks to create a concise function returning true if number is even using bits.
bool isEven(int num) {
return (num [1] [2]) [3] 0;
}Use bitwise AND (&) with 1 and compare (==) to 0 to check if number is even.
