1293. Check if a Number is Divisible by 4

EasyBit ManipulationBit ManipulationDivisibilityBit Masking

Given a non-negative integer n, determine whether it is divisible by 4 by inspecting its lowest two bits instead of using the modulo operator. A number is divisible by 4 exactly when its last two bits are 0.

Input: A JSON object {"n": <non-negative integer>}.

Output: Return true if n is divisible by 4, otherwise false.

Examples

Example 1
Input: {"n":16}
Output: true
Explanation: 16 & 3 = 0, so 16 is divisible by 4 -> true.
Example 2
Input: {"n":18}
Output: false
Explanation: 18 & 3 = 2, so 18 is not divisible by 4 -> false.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →