I have an array of char containing binary string, let's call it binString. I also have another array of character that has a few characters, let's call it asciiString. I want to convert each asciiString character to binary string.
For instance, binString will have: "00001101". And asciiString will be: "ba". Now I want to convert b to binary which is "01100010" and append to binString. Also convert char 'a' to bin and do the same. If there is a character like "2", first need to convert to int, then convert to bin, so "2" should result in "00000010".
Here is my code so far:
char *asciiToBin(int value, int bitsCount)
{
char *output[16];
int i;
output[bitsCount - 1] = '\0';
for (i = bitsCount - 1; i >= 0; --i, value >>= 1)
{
output[i] = (value & 1) + '0';
}
return output;
}
Now, from another function:
position = 8; // this is filled up to this character
char *binString[32];
len = 16;
bin16 = asciiToBin(atoi(operand), len);
for (int x = 0; x < len; x++)
{
char c = bin16[x];
binString[position + x + 1] = c;
}
Can someone help please?
Thanks,
outputreally be an array of 16char*?len = sizeof(int)*CHAR_BIT + 1;