You can use a fact that every odd number have 1
at the end of its binary representation so it looks like ???????1
where ?
can be either 0 or 1. Here is how you can check it with binary AND -> &
public static boolean isEven(int num) {
return (num & 1) == 0;
}
It works like this:
for odd numbers
????????1 -> any odd number
000000001 -> one
AND ---------
result 000000001 -> one
for even numbers
????????0 -> any even number
000000001 -> one
AND ---------
result 000000000 -> zero