Last active
October 10, 2017 17:20
-
-
Save polaris/ad4571f9d192388470123a518462fb41 to your computer and use it in GitHub Desktop.
Compute the parity of a word
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
short parity(unsigned long x) { | |
short result = 0; | |
while (x) { | |
result ^= 1 | |
x &= (x - 1); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment