Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- const int m1 = 1431655765; // binary: 0101...
- const int m2 = 858993459; // binary: 00110011...
- const int m4 = 252645135; // binary: 0000111100001111...
- int main()
- {
- int a, b;
- scanf("%d %d", &a, &b);
- int result = a ^ b;
- result = (result & m1 ) + ((result >> 1) & m1 ); //put count of each 2 bits into those 2 bits
- result = (result & m2 ) + ((result >> 2) & m2 ); //put count of each 4 bits into those 4 bits
- result = (result & m4 ) + ((result >> 4) & m4 ); //put count of each 8 bits into those 8 bits
- printf("%d", 7 - result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement