i have an argb value in the parameter of a function and the function needs to get rid of the agb values and only keep the r. How would you do that? thank-you
+2
A:
That is done with bitwise shifting and bitwise AND.
The uint in a 32 bit integer. Each of the A,R,G,B takes up 8 of its bits(one byte). And they appear I the same order as the name implies A,R,G,B
To get out b you just need to mask out all the other bits with a bitwise AND statement.
a=argb&255 because 255 in binary is 11111111, it only keeps the needed bits.
for g you first need to shift the bits then do the above. g=argb>>8&255
r is same but shift 16 bits
r=argb>>16&255
and a a=argb>>24&255
Hope that helps
Clox
2009-08-03 10:01:42
WoahI think I will have to read up on bitwise operatorsThanks
2009-08-03 10:02:23
Heh, it's good to know about them. They can optimize certain things quite a bit. Plus, in my opinion they're fun ^^Here's an example where it could speed up things quite a bit. It's sort of complicated though, but intreresting =)http://onjava.com/pub/a/onjava/2005/02/02/bitsets.html?page=2
Clox
2009-08-03 10:56:07
+2
A:
here's more information on it: http://www.adobe.com/devnet/flash/articles/bitwise_operators_print.html