My implementation of a binary-to-bits converting function:
#include <stdio.h>
#include <limits.h>
unsigned char *return_byte (unsigned char source)
{
static unsigned char byte[CHAR_BIT];
unsigned char *p = byte, i;
for(i = 0; i < CHAR_BIT; i++)
p[i] = '0' + ((source & (1 << i)) > 0);
return p;
}
int main(void)
{
unsigned char val = 200;
printf("Value:\t%i\nBinary:\t%s", val, return_byte(val));
return 0;
}
Output:
Value: 200 Binary: 00010011