D
David Vestal
I'm reading a 24-bit address from a char* named i_msg, and I expected these
two snippets to be equivalent. They aren't; the first doesn't work. What
gives?
SNIPPET 1:
unsigned long address;
address = ((unsigned long) i_msg[2]) << 16
+ ((unsigned short) i_msg[3]) << 8
+ i_msg[4];
SNIPPET 2:
unsigned long address;
address = i_msg[2];
address <<= 8;
address += i_msg[3];
address <<= 8;
address += i_msg[4];
two snippets to be equivalent. They aren't; the first doesn't work. What
gives?
SNIPPET 1:
unsigned long address;
address = ((unsigned long) i_msg[2]) << 16
+ ((unsigned short) i_msg[3]) << 8
+ i_msg[4];
SNIPPET 2:
unsigned long address;
address = i_msg[2];
address <<= 8;
address += i_msg[3];
address <<= 8;
address += i_msg[4];