Created
August 18, 2020 14:17
-
-
Save NovemberDev/14807e6e968f374bb687c9f3787d503d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static bool IsEven(int i) { | |
return (i & 1) == 0; | |
} | |
/* | |
Returns if the given integer is even using Bitwise & AND operator: | |
1010 equals 10 in decimal | |
0001 equals 1 in decimal | |
0000 AND returns 0 so it is even (0 of 10, 1 of 1) | |
0011 equals 3 in decimal | |
0001 equals 1 in decimal | |
0001 AND returns 1 so it is uneven (1 of 3, 1 of 1) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment