News for hackers. Stuff that matters.
Re:Test if a number is even by maplet on Saturday January 11, 2025 @04:53PM (#42669223)
You can actually generalize i % 2 == i & 1 to larger powers of 2.

Using C Syntax,

i % (1 << n) == i & ((1 << n) - 1)

holds for unsigned integer n and (1 << n) is 2 to the power of n.

Re:Test if a number is even by tptacek on Tuesday January 14, 2025 @07:23PM (#42705825)
... or just let the compiler do that for you.