Efficient code for....byte count
Following is the program u can use :
these two lines where i and k are initialized with 0 and byte is the variable to in which
no of 1is being counted.
while(k<8)
i+=(byte>>k++)&&0x01;
sorry i didn't got any clue for this solution without shif operator.
#include
void main(){
unsigned char byte;
byte=0x0f;
int i=0,k=0;
while(k<8)
i+=(byte>>k++)&&0x01;
printf("\nno of '1' :%d",i)
}
Thursday, June 24, 2004
Posted by Dinakar at Thursday, June 24, 2004
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment