DEV Community

Cover image for 6 tips you must know to master bit operation
Pragyan Tripathi
Pragyan Tripathi

Posted on

6 tips you must know to master bit operation

Bit operation is useful in algorithms and can be much faster than arithmetic operations.

Here are 6 tips you must know to master it:

  1. Before learning bit operation, you should know how decimal converts to binary and how binary turns to decimal. Here is a simple calculation method.

Image description

2. Shift Arithmetic Left <<

Shift arithmetic left is to move all the binary to the left.

Image description

3. Shift Arithmetic Right >>

The bitwise right shift moves all the binary digits to the right and removes the extra left digit.

Image description

4. Bitwise And

Each bit is 1, and the result is 1

Image description

5. Bitwise Or

One of bit is 1, and the result is 1

Image description

6. Bitwise XOR

Each bit is different, and the result is 1

From the below code, we can find that the bitwise XOR is the not carry addition.

Image description

Thanks for reading this.

If you have an idea and want to build your product around it, schedule a call with me.

If you want to learn more about DevOps and Backend space, follow me.

If you want to connect, reach out to me on Twitter and LinkedIn.

Top comments (0)