Showing posts with label Bitwise. Show all posts
Showing posts with label Bitwise. Show all posts

Monday, June 28, 2010

Find Zeros and One

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: }