1294. Check if a Number is Divisible by 8

EasyBit ManipulationBit ManipulationDivisibilityBit Masking

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

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

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

Examples

Example 1
Input: {"n":64}
Output: true
Explanation: 64 & 7 = 0, so 64 is divisible by 8 -> true.
Example 2
Input: {"n":12}
Output: false
Explanation: 12 & 7 = 4, so 12 is not divisible by 8 -> false.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →