This code works, but I'm wondering if there is a better way to do it. Basically I need to test bits, and write the appropriate character or characters to a string depending on the state of the bit. The spaces are present because the characters will be displayed with a fixed width font and I'd like to keep them from moving around. C or C++ is fine.
const char* Letters[10] = {"A", "B", "Sl", "St", "R", "L", "U", "D", "RS", "LS"};
const char* Ext[2] = {"X", "Y"};
const char* Spaces[10] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " "};
char str[60];
char FinalString[60];
void MakeBitString(u16 data, u16 dataExt) {
int x;
strcpy(str, "");
for (x = 0; x < 2; x++) {
//X and Y
if(dataExt & (1 << x)) {
strcat(str, Spaces[x]);
}
else
strcat(str, Ext[x]);
}
for (x = 0; x < 10; x++) {
//the rest
if(data & (1 << x)) {
strcat(str, Spaces[x]);
}
else
strcat(str, Letters[x]);
}
strcpy(FinalString, str);
}