Hi, I'm having problems assembling a set of 4 bytes into a long int. My approach has been this:
ulong temp; temp = (temp << SHIFT_BYTE) | getByte(); temp = (temp << SHIFT_BYTE) | getByte(); temp = (temp << SHIFT_BYTE) | getByte(); temp = (temp << SHIFT_BYTE) | getByte(); return temp;
I did read back a few months worth of forum discussion before posting, but I didn't search the knowledge base. Thanks for responding anyway. There's more Keil-specific stuff than just the byte ordering in a long. The original purpose of my post was to find out which C code the compiler converted into efficient assembly. An intelligent enough compiler should have produced the same code for both the union approach and the shift approach, in which case, I would have opted for the portable approach. In my pre-purchase testing of the Keil compiler, I had found that it generally was very good at efficient assembly code for constant math such as dividing or multiplying by constant that is a power of 2 (shifting). I guess I was just expecting too much. The Keil tools do generally do a very good job. Thanks, Bob