Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- int getBitsParity(uint32_t x) {
- int parity = 0;
- if (x) {
- do {
- parity ^= 1;
- } while(x &= x - 1);
- }
- return parity;
- }
- int main(void) {
- uint32_t x;
- printf("x="); scanf("%u", &x);
- printf("bits parity: %d\n", getBitsParity(x));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement