C programming question

Thread Starter

Art

Joined Sep 10, 2007
806
Hi Guys,
Have a small problem.
How can I get four values out of a 32 bit variable into four seperate bytes (or u8 vars)
like this:

32bitvar = 11223344;

do something here

u8a = 11;
u8b = 22;
u8c = 33;
u8d = 44;


assistance would help me out of a jam!
I'm essentially trying to split a 32bit pixel value into seperate alpha, red, green & blue values.
 

RiJoRI

Joined Aug 15, 2007
536
Rich (BB code):
bigVar = 11223344;

byteD = (uchar)(bigVar & 0xFF);

bigVar >>= 0x10;

/* Continue with byteC, byteB,and byteA */
Now whether you continue linearly, or build a loop is up to you.

--Rich
 
Top