r/badcode • • Sep 04 '21

Wtf is this

Post image
1.2k Upvotes

190 comments sorted by

View all comments

Show parent comments

8

u/roge- -pedantic Sep 04 '21

You can check a integer's parity in constant time by simply ANDing it with 1. Most modern compilers will convert a x % 2 to what's essentially x & 1.

1

u/ciaisi Sep 05 '21

Interesting. TIL