consider this:
a message like this: {0x01, 0x01, 0x01, 0x01}
can be parsed as
00000001 00000001 00000001 00000001(bin) = 16.843.009(dec)
so you just need to take every char and shift them according to its position
i.e.
char0 not shifted at all,
char1 shifted 8 positions to the left (or multiply by 2^8)
char2 shifted 16 positions to the left (or multiply by 2^(8*2))
char3 shifted 24 positions to the left (or multiply by 2^(8*3))
unsigned int procMsg(Message &x)
{
return (x.three << 24) |
(x.two << 16) |
(x.one << 8) |
x.zero;
}
int main(int argc, char *argv[])
{
//0 1 2 3
Message myMsg[4] = {{0x01, 0x01, 0x01, 0x01}, //00000001 00000001 00000001 00000001 = 16.843.009
{0xFF, 0x00, 0xAA, 0xCC}, //00000001 00000001 00000001 00000001 = 3.433.693.439
{0x01, 0x00, 0x00, 0x00}, //00000001 00000001 00000001 00000001 = 1
{0x00, 0x00, 0x00, 0x00} //00000000 00000000 00000000 00000000 = 0
};
for (int i = 0; i<4; i++)
{
Message x = myMsg[i];
std::cout << "res: " << procMsg(myMsg[i]) << std::endl;
}
return 0;
}