I have a long number. Now what I want is following (given in pseudo code) ,
int cnt1 = 0
int cnt2 = 0
for each two bits of that long
if the two bi
What you need to do is create a bit-mask and run it over your value, assuming this is homework I will only give some pointers:
long mask = 0x03L;
&
to check a value against a maskIf you put above hints into code, you will have your answer :-)
Edit now that the results are in, my solution would be:
long cnt1 = 0;
long cnt2 = 0;
for (long mask = 0x03; mask != 0; mask <<=2) {
(mask == (value & mask)) ? cnt1++ : cnt2++;
}