This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Equivalent code?

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];

I want to combine the four bytes of data from the array and store it as an unsigned long in seq_address. I first tried the code in the first example but it does not work (seq_address is always 0). The code in the second example works. Does anyone see a reason both examples should not do the exact same thing.

-Walt

0