I'm not really sure what you want to do, but maybe the program below will give you an idea (?)
Code:
#include <stdio.h>
#include <limits.h>
int main(void)
{
const unsigned char testbyte = 100;
int i;
for (i = CHAR_BIT - 1; i >= 0; --i) {
if ((testbyte & 1 << i) != 0)
printf("1");
else
printf("0");
}
printf("\n");
return 0;
}
Edit: If you want to go from LS bit to MS bit, which it seems you want to, then the following is probably better
Code:
#include <stdio.h>
#include <limits.h>
int main(void)
{
const unsigned char testbyte = 100;
int i;
for (i = 0; i < CHAR_BIT; ++i) {
if ((testbyte & 1 << i) != 0)
printf("1");
else
printf("0");
}
printf("\n");
return 0;
}