Based on what you've said in your comments, it sounds like you want to get a stream of bits from the ASCII representation of a string like "red"
. You can do that by looping over each character of the string, and then looping over each bit position:
const char *str = "I hate programming";
// Loop over each character
for (i = 0; i < strlen(str); i++)
{
// Loop over each bit
for (j = 0; j < 8; j++)
{
// Extract bit #j of character i, using bit-shift and mask
bit = (str[i] >> j) & 1;
// bit will be 0 or 1, so do something with it here
}
}
If you want the bits in each character in the opposite order, then just reverse the order of the inner (j
) loop.
Note that as @unwind says in his answer, this has nothing to do with actually generating an audio waveform for spoken words.