Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resources to learn bitwise programming? [closed]

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!

like image 831
JimDaniel Avatar asked Jul 22 '09 20:07

JimDaniel


People also ask

Is bit manipulation difficult?

Bit manipulation, in some cases, can obviate or reduce the need to loop over a data structure and can give many-fold speed-ups, as bit manipulations are processed in parallel, but the code can become more difficult to write and maintain.

Are bitwise operators important for competitive programming?

Playing with bits can be fun with competitive programming. The bits work faster by reducing your execution time as it is the greatest factor in competitive programming. Faster the execution time better the code performance. So, let's know about the major hacks that can be done at a bit level to optimise the code.

Why is bit manipulation useful?

For most other tasks, modern programming languages allow the programmer to work directly with abstractions instead of bits representing those abstractions. Bit manipulation can obviate or reduce the need to loop over a data structure and can speed up coding as bit manipulations are processed in parallel.


2 Answers

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.

like image 102
Boojum Avatar answered Sep 22 '22 12:09

Boojum


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.

like image 26
nos Avatar answered Sep 20 '22 12:09

nos