Skip to content

Instantly share code, notes, and snippets.

@mooware
Created January 6, 2015 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooware/1796c15d0cbca0fe1c30 to your computer and use it in GitHub Desktop.
Save mooware/1796c15d0cbca0fe1c30 to your computer and use it in GitHub Desktop.
Bit operations to determine whether a month has 31 days
# Bit operations to determine whether a month has 31 days.
# Just for fun, inspired by an example in the Coursera course
# 'Hardware Security', https://www.coursera.org/course/hardwaresec
def has31days(month):
return (month & 1) ^ ((month & 8) >> 3)
for i in range(1, 13):
print(i, has31days(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment