I have a query on selection of method to extract a byte from the word. My word is currently unsigned. It is simply collection of 32 bits.(1s and 0s). Both the follwing script I implement returns me same result. I wonder which is a better option to select.
Bytes0=(UINT8)((Word>>00 & 0x0000FF);
Bytes1=(UINT8)(Word>>08 & 0x0000FF);
Bytes2=(UINT8)(Word>>16 & 0x0000FF);
Bytes3=(UINT8)(Word>>24 & 0x0000FF);
or
Bytes0=(UINT8)((Word>>00);
Bytes1=(UINT8)(Word>>08 );
Bytes2=(UINT8)(Word>>16 );
Bytes3=(UINT8)(Word>>24 );
Am I missing something?
Thanks
DSP Guy
The cast to UINT8 is discarding all the bytes except for the lowest one. So in the first case, you convert the upper bytes to 0 and then discard them; in the second you simply discard them. The second option is clearly more efficient, assuming you are assigning to a UINT8.