I have read up on them, but they don't seem so simple. Maybe you could explain them, if you don't think i'll understand...
But if you don't understand the material you find in your book or with Google, then you won't understand our explanations either. If there's a concept you don't understand, something about the material you don't get, you need to tell us what it is you don't understand.
All you have to do is explain to me this bit shifting and bits in general. Then how i would use it for the concept of RGB.
The concept can be explained with a Google search. You complain you don't understand the material. How do we know our explanation won't be wasted on you?
Moreoever, figuring out how to use bit shifting for RGB
is the homework assignment. You need to think about it. As far as we can tell, you just want the answer, and you'll take the explanation if you feel like it.
I'll give you a short description of bits and bit shifting. Let's see if you go anywhere with this.
A bit can be thought of as an on/off switch, because that's effectively what it is in hardware. Let's call off 0 and on 1. These would be your binary digits. When it comes to numbers, bits can correspond perfectly with a binary number. Let's say you have two bits. You can have this.
-
Bit 1 Bit 0 Binary Number Decimal Number
-
0 0 00 0
-
0 1 01 1
-
1 0 10 2
-
1 1 11 3
-
Can you see a pattern with how many bits you need to have how large a number? R, G, and B go from 0 to 31. How many bits do they need minimum?
Now consider bit shift. As it sounds, it's simply a shift:
0010 << 1 becomes 0100
0001 << 3 becomes 1000
It's the reverse direction for >>.
Now think. Knowing how many bits there are in R, G, and B, and using bit shifting, how can you form a 16 bit "number" from R,G, and B?