Created
March 31, 2010 06:59
-
-
Save fjenett/350026 to your computer and use it in GitHub Desktop.
Is int even?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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