example:
unsigned char foo[5] = {0x01, 0x02, 0x03, 0x04, 0x05};
short bar;
//bar should be the 2 byte value spanning foo[1] and foo[2];
bar = (short)(foo[1] ) + (short)(foo[2] * 256); //this is correct.
I can do it this way but i was wondering if there was a casting mechanism to accomplish this without explicity addressing the two separate elements.
//Something like this...
//will only copy the 8 bit value in foo[1].
bar = (short)(*(foo + 1));
suggestions?
2007-08-22
05:27:48
·
4 answers
·
asked by
Joe
4
in
Computers & Internet
➔ Programming & Design