# The Bitwise Judge

> No division, no modulo - just a single bit tells you everything.

Canonical URL: <https://datadriven.io/problems/the_bitwise_judge>

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given an integer n (possibly negative), return True if n is even, False if odd. Solve using bitwise operations only - no %, no /, no //.

## Worked solution and explanation

### Why this problem exists in real interviews

Checking even/odd with bitwise AND tests the most basic **bit manipulation** concept: the least significant bit determines parity.

---

### Break down the requirements

#### Step 1: Check the least significant bit

If `n & 1` is 0, the number is even. If 1, it is odd.

---

### The solution

**LSB check for parity using bitwise AND**

```python
def is_even(n):
    result = (n & 1) == 0
    return result
```

> **Time and Space Complexity**
>
> **Time:** O(1). A single bitwise operation.
> 
> **Space:** O(1).

> **Interviewers Watch For**
>
> Using `n & 1` instead of `n % 2`. Both are correct, but the bitwise approach is the expected answer when the prompt prohibits modulo.

> **Common Pitfall**
>
> Forgetting that `n & 1` returns an integer (0 or 1), not a boolean. You must compare `== 0` to get a boolean result.

---

## Common follow-up questions

- How would you check if a number is a power of 2? _(Tests `n > 0 and (n & (n - 1)) == 0`, which checks that only one bit is set.)_
- What if n is negative? _(Tests that bitwise AND on negative numbers in Python works with two's complement, and the LSB check still determines parity.)_
- Can you check divisibility by 4 using bitwise operations? _(Tests `(n & 3) == 0`, checking the two least significant bits.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/the_bitwise_judge)
- [Python Interview Questions](https://datadriven.io/python-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.