A leap year check in three instructions

How to test for leap years (until year 102499) in the proleptic Gregorian calendar with just three 32-bit instructions, with detailed explanation of the bit-level tricks.

The mother lode of #BitTwiddling tips (apart from the #book “Hacker’s Delight”, by Henry S. Warren Jr, and “HAKMEM” by the MIT hackers):

“Bit Twiddling Hacks”, Sean Eron Anderson (https://graphics.stanford.edu/~seander/bithacks.html).

On HN: https://hn.algolia.com/?dateRange=all&page=0&prefix=false&query=Bit%20Twiddling%20Hacks&sort=byPopularity&type=story

#Math #Optimization #Compilers

Bit Twiddling Hacks