1: #include <stdio.h>2:3: main()4: {5: int val = 1;
6: int data = 10;
7: int OneCount = 0;
8: int ZeroCount = 0;
9: while(val)
10: {11: if(data & val)
12: OneCount++;13: else
14: ZeroCount++;15:16: val = val << 1;17: }18: printf("Number of ones %d \n",OneCount);19: printf("Number of zeroes %d \n",ZeroCount);20: getchar();
21: }
- output will be
- number of ones is 2
- number of zeros is 30 (int is 4 bytes)
No comments:
Post a Comment