Hi All,

I have been programming for a while, currently a junior CS student. Programming has always felt very natural to me and I pick up new concepts quickly and I generally retain most of what I learn. However, when it comes to converting between Dec/Bin/Hex as well as performing bitwise operations, I have never really been able to retain the process. Also, the problem is that every programming book that I have accumulated over the years always seems to only touch on the subject lightly, like a quick review. I am looking to find some good, in depth and intuitive reading about converting between the three and also mastering bitwise operations. I know this is something that is covered in basic courses but for some reason I have never been able to really master it.

The best way to think about decimal, hex, octal, and binary conversions is to understand how numeral counting systems work. In decimal, we count like this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and then because we don't have a single symbol higher than 9, we have to add another decimal place. This gives us 10. We can keep counting from there, 11, 12, 13, 14, etc. In hex, you count the same way, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, but here's where it gets tricky. Hex defines the symbols a, b, c, d, e, and f to mean 10, 11, 12, 13, 14, and 15 respectively. That means you count like this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10. See, you get to 16, and you've run out of single symbols that can represent a value, so you have to add another decimal place (although I guess here it's a hexadecimal place.) Binary and octals work the same way, but instead they count to 7 and 1, respectively, before requiring another decimal place.

So far as binary operations are concerned, I don't really feel like explaining them, so here's the tutorial I learned off of: http://www.learncpp.com/cpp-tutorial/38-bitwise-operators/

Hopefully this cleared things up, though admittedly the hex/dec/oct things always make my head hurt.

This article has been dead for over six months. Start a new discussion instead.