## Program to find position of rightmost set bit

Example :
Input 10 , binary form 1010
Output 2
Algorithm :
1. Take two's complement of the given no as all bits are reverted
except the first '1' from right to left (10111)
2 Read more ...

Example :
Input 10 , binary form 1010
Output 2
Algorithm :
1. Take two's complement of the given no as all bits are reverted
except the first '1' from right to left (10111)
2 Read more ...

A rotation (or circular shift) is an operation similar to shift except that the bits that fall off at one end are put back to the other end.
In left rotation, the bits that fall off at left end are Read more ...

C function that unsets the rightmost set bit of an integer.
Examples:
Input: 10 (00...01010)
Output: 8 (00...01000)
Input: 7 (00...00111)
Output: 6 (00...00110)
Let the input number be n. Read more ...

Method 1 :
A simple method for this is to simply take the log of the number on base 2 and if you get an integer then number is power of 2.
Method 2:
If we subtract a power of 2 numbers by 1 then Read more ...

Method 1:
Loop through all the bits of an integer. If a bit at ith position is set in the i/p no. then set the bit at (NO_OF_BITS – 1) – i in o/p. Where NO_OF_BITS is number of bits present in the Read more ...

Method 1 :
Simple Method Loop through all bits in an integer, check if a bit is set and if it is then increment the set bit count. See below program.
int countSetBits(unsigned int n)
{
unsigned Read more ...

Method 1 .
A simple method is to take log of the given number on base 4, and if we get an integer then number is power of 4.
Method 2.
Another solution is to keep dividing the number by 4, i.e, do Read more ...

Program to add one to a given number. You are not allowed to use operators like ‘+’, ‘-’, ‘*’, ‘/’, ‘++’, ‘–’ …etc.
Examples:
Input: 8
Output: 9
We can use bitwise operators Read more ...