Complete the code to check if a number is even using bitwise AND.
function isEven(num) {
return (num & [1]) === 0;
}The bitwise AND with 1 checks the least significant bit. If it is 0, the number is even.
Complete the code to check if a number is odd using bitwise AND.
function isOdd(num) {
return (num & [1]) === 1;
}Bitwise AND with 1 isolates the least significant bit. If it is 1, the number is odd.
Fix the error in the code to correctly check if a number is even using bits.
function checkEven(num) {
if ((num [1] 1) === 0) {
return true;
} else {
return false;
}
}The bitwise AND operator (&) is used to check the least significant bit to determine evenness.
Fill both blanks to complete the function that returns 'Even' or 'Odd' using bitwise operation.
function evenOrOdd(num) {
if ((num [1] [2]) === 0) {
return 'Even';
} else {
return 'Odd';
}
}Using bitwise AND (&) with 1 checks the least significant bit. If it is 0, the number is even; otherwise, odd.
Fill all three blanks to create a concise function returning true if number is odd, false otherwise.
const isOdd = num => (num [1] [2]) [3] 1;
The function uses bitwise AND (&) with 1, then checks if the result is equal (===) to 1 to determine oddness.
