Bit Switching and Other Stuff
I was wondering if anyone knew a good place to finda a tutorial on some stuff I''m a bit foggy on in c++. Mainly I dont understand whats going on here except for on a basic level.
USHORT color;
UCHAR r;
r = (color & 0xF800) >> 11;
Basicly its the last line there with the memory bit and the bit shifts. Thanks for any help in adcance.
the & part takes only the top 5 bits of the big number, and the >> part moves them down to the bottom five bits.
Well 0xF800 is 1111 1000 0000 0000 so if you perform a bitwise and on that with some other value you will get ???? ?000 0000 0000. If you shift that right 11 times you just get ? ????, which is the red component of a 32 bit color value.
[edit] Just to expand a little on the AP.
[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people
[edited by - wild_pointer on November 29, 2003 9:31:03 PM]
[edit] Just to expand a little on the AP.
[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people
[edited by - wild_pointer on November 29, 2003 9:31:03 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement