Skip to content

Instantly share code, notes, and snippets.

@fjenett
Created March 31, 2010 06:59
Show Gist options
  • Save fjenett/350026 to your computer and use it in GitHub Desktop.
Save fjenett/350026 to your computer and use it in GitHub Desktop.
Is int even?
// quickly find out if an int is even or uneven with:
// (i & 1) == 0
// ... which "extracts" the last bit.
for ( int i = 0; i < 10; i++ )
println( i + " " + (i & 1) + ( (i & 1) == 0 ? " even" : " uneven" ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment