Archived

This topic is now archived and is closed to further replies.

Bit Switching and Other Stuff

This topic is 5130 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the & part takes only the top 5 bits of the big number, and the >> part moves them down to the bottom five bits.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites