I have been programming for the past 3 years and haven’t really put in efforts to write bit manipulation code. Having worked on enterprise software, I haven’t seen other developers write it either.
Is it a good practice to write a bit manipulation code instead of using the mathematical operations for performing calculations?
More or less, if you’re not working with the kind of software that would benefit from bit manipulation, then you probably don’t need to be using them. In fact, in many places they can make code harder to read, and really shouldn’t be used unless there is a reason to.
However, if you’re interested, they are a useful tool given the right application. For example, if you have code which is multiplying by a power of two, it can be quicker to just left shift the bits. This can become important if you determine that the multiplication code is a bottleneck to performance.
One important fact to realize is that some compilers will do some of these forms of optimization (e.g. turning the line
i = i * 2into a left shift) for you.