Bit manipulation techniques every programmer should know Part - 0
Bit manipulation
Bit manipulation is the technique of doing some of the basic arithmetic operations using bit-wise operators. It is the fastest way to perform some of the basic operations that we use in our day-to-day programming tasks. We all know t...
prabanjanraja.hashnode.dev3 min read
Akash Poddar
Software development Engineer
swapping two number a and b: a=a^b b=b^a a=a^b
Exctract ith bit from binary nuber
int getithbit(int n, int i) int mask=(1<<i); return n & mask!=0?1:0;
set the ith bit
int getithbit(int n, int i) return n | (1<<i)!=0?1:0;
clear the ith bit to 0 clearBit(int n, int i){ int mask= ~(i<<i); n= n & mask;