Getting out the r-channel from a argb-uint?
-
10-07-2019 - |
Question
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
Solution
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
OTHER TIPS
here's more information on it: http://www.adobe.com/devnet/flash/articles/bitwise_operators_print.html