fastest way to access the 8 MSB of an (unsigned) int?

Hello,

what is the fastest way to access the 8 MSB of an (unsigned) int on the device?

Right now I’m doing it by shifting right 24bits.

Code sniplet:

unsigned int a,b;

a = 0x12345678;

b = a >> 24;

a &= 0xFFFFFF;

/* in this example a is 0x345678 and b is 0x12 now */

So I’m wondering if there is a faster way, e.g. cast “a” to a packed uchar and read the specific byte.

Regards,

Oliver

The shift is already a single clock instruction… no need to optimize it further.

unsigned int a;

unsigned char bytes[4];

*(unsigned int *)bytes = a;

Now bytes[3] - most significant 8 bits, byte[2] is the next 8 and so on… (Assuming little endian)

Simble, no?