??? 02/13/09 09:18 Read: times |
#162350 - Shift-and-Mask = Portable, and possibly not slow Responding to: ???'s previous message |
The Shift-and-Mask approach outlined by Per is completely portable and completely general - it can be adapted for extracting any sized portions out of any (larger) sized word on any platform.
Depending on the compiler, it may not even be any slower than the union... Here it is again: u24_t var24; // Some assumed 24-bit (3-byte) tytpe // Shift as required Mask-off the required portion // ----------------- ----------------------------- unsigned char low = var24 & 0xff; unsigned char middle = (var24 >> 8) & 0xff; unsigned char high = (var24 >> 16) & 0xff; |
Topic | Author | Date |
LSB byte of 24 bits | 01/01/70 00:00 | |
a union | 01/01/70 00:00 | |
union = fast, but not portable | 01/01/70 00:00 | |
Shift-and-Mask = Portable, and possibly not slow | 01/01/70 00:00 | |
Shifts and masks often resulting in optimum native code | 01/01/70 00:00 | |
can be portable | 01/01/70 00:00 | |
Can be portable | 01/01/70 00:00 | |
More to it than that! | 01/01/70 00:00 | |
which is why I do this very thing | 01/01/70 00:00 | |
for completeness there is the pointer | 01/01/70 00:00 | |
Split the word? | 01/01/70 00:00 | |
Tautology? | 01/01/70 00:00 | |
re: Tautology | 01/01/70 00:00 | |
possible, but not universal![]() | 01/01/70 00:00 | |
thank you | 01/01/70 00:00 |