Bit AlgorithmsThis is arrays page Check if a given number is even or oddGiven a number,check if it is even or odd using bit operations. Algorithm: let num be x find x&1 ,if result is 0 then even else odd. The Least sign... Check if a given number is power of twoGiven a number,check if it is power of 2 or not without using division or modulo operator. Count number of set bits in binary notationGiven a number “n”,count the number of set bits in it. Algorithm(Brian Kernighan’s method): 1. set count=0 2. while n>0 set n:=n&(n-1) incre... Unset the least significant bitGiven a binary number unset the rightmost set bit. Algorithm: The biwise “&” of any number n with n-1 unsets the rightmost set bit e.g. 5=101 ,5-1=4=100 ...
Check if a given number is even or oddGiven a number,check if it is even or odd using bit operations. Algorithm: let num be x find x&1 ,if result is 0 then even else odd. The Least sign...
Check if a given number is power of twoGiven a number,check if it is power of 2 or not without using division or modulo operator.
Count number of set bits in binary notationGiven a number “n”,count the number of set bits in it. Algorithm(Brian Kernighan’s method): 1. set count=0 2. while n>0 set n:=n&(n-1) incre...
Unset the least significant bitGiven a binary number unset the rightmost set bit. Algorithm: The biwise “&” of any number n with n-1 unsets the rightmost set bit e.g. 5=101 ,5-1=4=100 ...