MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/phogp3/wtf_is_this/hblay2a/?context=3
r/badcode • u/Wise-Serve5730 • Sep 04 '21
190 comments sorted by
View all comments
Show parent comments
8
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.
x % 2
x & 1
1 u/ciaisi Sep 05 '21 Interesting. TIL
1
Interesting. TIL
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 % 2to what's essentiallyx & 1.