C > Miscellaneous
Test bits
Test bits #include
int main(void) { char byte = 67; int bitcount = 8; /* supposed bits in a byte */ printf("char byte = 67 or binary "); for(; bitcount > 0; bitcount--) { /* if the high order bit is set [left one], print `1' */ printf("%d", (byte & 128) ? 1 : 0 ); byte <<= 1; /* push all bits to the left */ } printf("\n"); return 0; }
C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting