1265. Check if a Number is Even or Odd Using Bit

EasyBit ManipulationBit ManipulationBitwise ANDParity

Given an integer n, determine whether it is even using a single bitwise operation instead of the modulo operator. A number is even when its least-significant bit is 0. Return true if n is even and false if it is odd.

Input: A JSON object {"n": <integer>} where n may be negative, zero, or positive.

Output: Return the boolean true if n is even, otherwise false.

Examples

Example 1
Input: {"n":4}
Output: true
Explanation: 4 is 100 in binary; the last bit is 0, so 4 is even -> true.
Example 2
Input: {"n":7}
Output: false
Explanation: 7 is 111 in binary; the last bit is 1, so 7 is odd -> false.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →