void updatebit(int &n,int i,int v)
{
int mask=(~1<<i);
int cn=n&mask;
n=cn|(v<<i);
}
here for n=5,i=1,v=1;
the code should output 7
but it is giving 6 why?
Bit masking question for update bit
correct one is
int mask=~(1<<i);
first right shift then take negation
i hope this help
if you have more doubts regarding feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course