views:

359

answers:

7

I am a c++ programmer and occasionally I'll come across some code that is using bitwise operators to manipulate things at the bit level, but I have no real understanding of those concepts. So I would like a resource to help me learn it so well that it becomes second nature. Does anyone know of good resources for this? A google search did not provide me much useful information. Maybe I'm not sure what to look for. Thanks!

+1  A: 

I imagine there are other possibly better resources, but I remembered that there was an article on this I read a few years ago on GameDev.Net.

BitWise Operations in C

Jorge Israel Peña
I just linked to that same one, It was in my Google Chrome bookmarks. It was a really good tutorial.
Lucas McCoy
+6  A: 

You'll have to know the background of the binary system. http://en.wikipedia.org/wiki/Binary_numeral_system has a great overview. Look at http://en.wikipedia.org/wiki/Bitwise_operation for bitwise operations.

nos
A: 

I would suggest the following tutorials:

http://www.cprogramming.com/tutorial/bitwise_operators.html http://www.codeproject.com/KB/cpp/bitbashing.aspx

They both have nice examples.

Evangelos
+7  A: 

I absolutely love Henry Warren's Hacker's Delight book. The website for it offers Chapter 2 ("Basics") as a free sample which, despite the name, offers some fairly sophisticated bit manipulation tricks. It might not be the best place to start, but it's fantastic once you start to get comfortable with bit arithmetic.

Boojum
+1 for Hacker's Delight - it's an excellent book which I'm constantly referring back to for fast ways to perform all sorts of algorithms
Dave Rigby
Also +1 for this great book. Though not all of the bit-twiddling is a win these days, it's still fascinating stuff.
Andy J Buchanan
Although there are lots of good web links listed, this book strikes me as just what I'm looking for. Thanks!
JimDaniel
+1  A: 

I agree with the responses above on that GameDev.net article. That was a good one for me in the past.

This article on Denormalization with Bitmasks (http://maggienelson.com/2009/02/denormalization-with-bitmasks/) was useful to me as well and includes database-specific examples, in case those are of use.

Mike Brittain