basics · beginner · ~15 min

Even number test

Use & to test the low bit.

Challenge

Implement int is_even(int n) returning 1 if n is even, else 0, using the bitwise AND operator.

Starter code

int is_even(int n) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.