Problem:
Count number of bits needed to be flipped to convert from integer A to B.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include <stdio.h> int main() { //code int t,a,b,c; int count=0; scanf("%d",&t); while(t--) { scanf("%d%d",&a,&b); c = a^b; count=0; while(c) { if(c&1) count+=1; c>>=1; } printf("%d\n",count); } return 0; } |