We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello Everyone: In the following example seq_address is an unsigned long and obj->cmd_reg[] is an unsigned char array.
seq_address = (ulong)obj->cmd_reg[3] << 24 + (ulong)obj->cmd_reg[2] << 16 + (ulong)obj->cmd_reg[1] << 8 + (ulong)obj->cmd_reg[0]; seq_address = (ulong)obj->cmd_reg[3] * 16777216 + (ulong)obj->cmd_reg[2] * 65536 + (ulong)obj->cmd_reg[1] * 256 + (ulong)obj->cmd_reg[0];
"+" has higher precedence than "<<". You wanted:
seq_address = ( (ulong)obj->cmd_reg[3] << 24 ) + ( (ulong)obj->cmd_reg[2] << 16 ) + ( (ulong)obj->cmd_reg[1] << 8 ) + (ulong)obj->cmd_reg[0];
Extra parentheses seem to have fixed it:
seq_address = ((ulong)obj->cmd_reg[3] << 24) + ((ulong)obj->cmd_reg[2] << 16) + ((ulong)obj->cmd_reg[1] << 8) + (ulong)obj->cmd_reg[0];
Ah, that make sense. Thanks a million. -Walt
FYI, Here is a link to the C precedence table: http://www.isthe.com/chongo/tech/comp/c/c-precedence.html Jon