Bitwise AND(&) Returns bit values of 1 for positions where both numbers had a one, and bit values of 0 where both numbers did not have one.
Bitwise OR(|) returns bit values of 1 for positions where either bit or both bits are one, the result of 0 only happens when both bits are 0.
Bitwise XOR(^) returns bit values of 1 for positions where both bits are different; if they are the same then the result is 0.
Bitwise Left-shift(<<) The bitwise left shift moves all bits in the number to the left and fills vacated bit positions with 0.
Bitwise RIght-Shift(>>) The bitwise right shift moves all bits in the number to the right.
NOTE: Where the left shift filled the vacated positions with 0, a right shift will do the same only when the value is unsigned. If the value is signed then a right shift will fill the vacated bit positions with the sign bit or 0, whichever one is implementation-defined. So the best option is to never right shift signed value
Two’s complement and negative number: The binary representation of -k as a N-bit number is concat(1, 2^(N-1)-k) ==representation in positive, flip each bit, and +1.
Bitwise Complement(~) The bitwise complement inverts the bits in a single binary number.
Checking Whether K-th Bit is Set or Not n & (1 ≪ K -1). If the expression is true then we can say the Kth bit is set
Setting K-th Bit: n | 1 ≪ (K – 1)
Clearing K-th Bit : n & ~(1 ≪ K – 1)
Toggling K-th Bit : n ^(1 ≪ K – 1)
Toggling Rightmost One Bit : n & n – 1
Isolating Rightmost Zero Bit : ~n & n + 1
Checking Whether Number is Power of 2 or Not : if(n & n – 1 == 0)
Multiplying Number by Power of 2 : to multiply the number with 2K we can use the expression: n ≪ K
Dividing Number by Power of 2 : divide the number with 2K we can use the expression: n ≫ K
Performing Average without Division We can use mid = (low + high) >> 1. Note that using (low + high) / 2 for midpoint calculations won’t work correctly when integer overflow becomes an issue. We can use bit shifting and also overcome a possible overflow issue: low + ((high – low)/ 2) and the bit shifting operation for this is low + ((high – low) >> 1)
binary numbers are 0 indexed REMEMBER left shifting a number by i multiplies that number with 2^i and right shifting by i divides it by 2^i
N-1 INVERTS EVERY BIT STARTING FROM RIGHTMOST ONE till INDEX ‘0’ IF N=0b00000110 N-1=0b00000101