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 Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay