Bit operation is useful in algorithms and can be much faster than arithmetic operations.
Here are 6 tips you must know to master it:
- Before learning bit operation, you should know how decimal converts to binary and how binary turns to decimal. Here is a simple calculation method.
2. Shift Arithmetic Left <<
Shift arithmetic left is to move all the binary to the left.
3. Shift Arithmetic Right >>
The bitwise right shift moves all the binary digits to the right and removes the extra left digit.
4. Bitwise And
Each bit is 1, and the result is 1
5. Bitwise Or
One of bit is 1, and the result is 1
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.
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)