Suppose your ints are 4 bytes each. 32 bit
A more understandable way:
Help: persistent array:
h[0]=3; for (int i=1; i<7; i++){ h[i]=h[i-1]*4; }
Later to check if c is an integer after bitwise XOR:
int count=0; for (int i=0; i<7; i++){ if(c&h[i]==0)count++; }
Another solution. Obviously faster, but a little less clear:
int h[4]={1,0,0,0} int count=0; for (int i=0; i<15; i++){ count+=h[c&3]; c=c>>2; }
Further qickening:
count= h[c&3] + h[(c=>>2)&3] + h[(c=>>2)&3] + h[(c=>>2)&3]+ h[(c=>>2)&3]+ h[(c=>>2)&3]+ h[(c=>>2)&3]+ h[(c=>>2)&3]+ h[(c=>>2)&3] + h[(c=>>2)&3]+ h[(c=>>2)&3]+ h[(c=>>2)&3]+ h[(c=>>2)&3]+ h[(c=>>2)&3]+ h[(c>>2)&3];
Besides:
int h[16]={2,1,1,1, 1,0,0,0, 1,0,0,0, 1,0,0,0}; count= h[c&15] + h[(c=>>4)&15] + h[(c=>>4)&15] + h[(c=>>4)&15] + h[(c=>>4)&15] + h[(c=>>4)&15] + h[(c=>>4)&15]+ h[(c>>4)&15];
If you really need to use the function so many (10 ^ 10) times, read h [256] (you already caught how) and use:
count= h[c&255] + h[(c=>>8)&255] + h[(c=>>8)&255] + h[(c>>8)&255] ;
I think the h [256 * 256] help array will also be useful. Then
count= h[c&255] + h[(c>>16)&(256*256-1)];
An array of 2 ^ 16 ints will be all in the processor's cash (third level, though). Thus, the speed will be very high.