Home > OS >  Zero all the bits after the 2nd index
Zero all the bits after the 2nd index

Time:01-08

i want to zero all the bits after the 2nd index (Including the 2nd) in an unsigned int. Here's the non working code i wrote so far: (temp is an unsigned int.)

for(int i=2; i< DSLength(dnaS); i  )
        {
            temp = temp & (0 << i);
        }

It keeps zeroing the whole number...

CodePudding user response:

If I understand you correct, and you want to preserve the lowest two bits and zero all the rest, you don't need a loop:

x &= 3

does exactly that with x.

  •  Tags:  
  • Related