Blog
Check If Kth Bit Is Set/Unset Using Left Shift
In the kth bit set/unset problem, we need to write a program that checks whether the kth bit of a number is either 1 or 0.
Arithmetic and Logical Right Shifts
The logical right shift means shifting the bits to the right, and MSB(most significant bit) becomes 0. The arithmetic right shift means shifting the bits to the right, and MSB is the same as in the original number.
Bitwise Left Shifts
The left-shift operator causes the bits in shift-expression to be shifted to the left by the number of positions specified by additive-expression. The bit positions that have been vacated by the shift operation are zero-filled.
Introduction to Bit Shifting
A bit shift is a Bitwise operation where the order of a series of bits is moved, either to the left or right, to efficiently perform a mathematical operation.
Solution Review: Missing Number
We solved the problem using lookup (hashtable), using the mathematical formula. Let's solve this more efficiently using bit-level operations with XOR and then optimize the solution.
Solution Review: Single Number
Single Number coding question, can be easily solved with XOR bitwise technique with linear time complexity.
Challenge 1: Single Number
In this lesson, every element appears twice except one element. We solve this using naive, and then we move to solve it more optimally using XOR operator.
Hamming Distance
Hamming distance talks about two integers where the bit positions where the corresponding bits are different.
Detect If Two Integers Have Opposite Signs
In this question, input two numbers and detect if they have opposite signs. We solve using bitwise XOR operator