I have been browsing some OpenJDK code recently and have found some intriguing pieces of code there that has to do with bit-wise operations. I even asked a question about it on StackOverflow. Another example that illustrates the point: 1141       public static int bitCount(int i) { 1142           // HD, Figure 5-2 1143           i = i - ((i >>> 1) & 0x55555555); 1144           i = (i & 0x33333333) + ((i >>> 2) & 0x33333333); 1145           i = (i + (i >>> 4)) & 0x0f0f0f0f; 1146           i = i + (i >>> 8); 1147           i = i + (i >>> 16); 1148           return i & 0x3f; 1149       }This code can be found in the Integer class. I cannot help but feel stupid when I look at this. Did I miss a class or two in college or is this not something I am supposed to just get? I can do simple bit-wise operations (like ANDing, ORing, XORing, shifting), but come on, how does someone come up with a code like that above?How good does a well-rounded programmer need to be with bit-wise operations?On a side note... What worries me is that the person who answered my question on StackOverflow answered it in a matter of minutes. If he could do that, why did I just stare like deer in the headlights?
How good does a well-rounded programmer need to be with bit-wise operations?
low level;bitwise operators
I would say that as a well-rounded developer, you need to understand the operators and bitwise operations.So, at a minimum, you should be able to figure out the code above after a bit of thinking.Bitwise operations tend to be rather low level, so if you work on websites and LOB software, you are unlikely to use them much.Like other things, if you don't use them much, you wouldn't be conversant in them.So, you shouldn't worry about someone being able to figure it out very quickly, as they (probably) work with this kind of code a lot. Possibly writing OS code, driver code or other tricky bit manipulation.