I testing a bit with different formats and stuff like that. And we got a task where we have to put uint32_t into char*. This is the code i use:
void appendString(string *s, uint32_t append){
char data[4];
memcpy(data, &append, sizeof(append));
s->append(data);
}
void appendString(string *s, short append){
char data[2];
memcpy(data, &append, sizeof(append));
s->append(data);
}
From string to char is simple and we have to add multiple uints into the char*. So now i'm just calling it like:
string s;
appendString(&s, (uint32_t)1152); //this works
appendString(&s, (uint32_t)640); //this also works
appendString(&s, (uint32_t)512); //this doesn't work
I absolutely don't understand why the last one isn't working properly. I've tested multiple variations of transform this. One way always gave me output like (in bits): 00110100 | 00110101 ... so the first 2 bits are always zero, followed by 11 and then for me some random numbers.. What am i doing wrong?