int RangeOfBits(int n,int i,int j)
{
int mask = (~0)<<(j+1);
int end = (1<<(i+1))-1;
mask = mask+end;
return n&mask;
}
this code is giving me incorrect answer. pls point out the mistakes in my code
int RangeOfBits(int n,int i,int j)
{
int mask = (~0)<<(j+1);
int end = (1<<(i+1))-1;
mask = mask+end;
return n&mask;
}
this code is giving me incorrect answer. pls point out the mistakes in my code
you don’t have to add these
instead take “OR” of both the masks
mask = mask || end;