Get the latest tech news
Test if a number is even
Problem You want to test if a number is even. Solution Well, the well-known solution is to test the value of n modulo 2. If it’s zero, then the number is even, otherwise it’s odd. But h…
Well, the well-known solution is to test the value of n modulo 2. You can use the bitwise AND operator and check the least significant bit of the integer. I think the optimizer recognizes modulo 2 and converts it to bitwise AND.
Or read this on Hacker News