Code:
itsme@itsme:~/C$ cat strtobin.c
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *str = "00111010";
printf("%s binary is %X hexadecimal\n",
str, (unsigned int)strtoul(str, NULL, 2));
return 0;
}
itsme@itsme:~/C$ ./strtobin
00111010 binary is 3A hexadecimal
And then you can use fwrite() to write 0x3A to the file. It's 1 byte containing all 8 bits.
EDIT: You're going to have to familiarize yourself with bit operations to work with this a lot. For instance, to grab the least significant bit you could do
int lsb = 0x3a & 1; and if you want the next least one you'd have to do
int nextlsb = (0x3a & 2) >> 1;
It's definitely possible to do this in C, you just need to know what you're doing.