DEV Community

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

Posted on

1

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.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more