bitbit-shiftbitstring

What happens when there is a NOT (~) on a bit shift operation


Just looking for some clarification on this homework question

The bitshift operation is ((1010 & ~(1 << 3))

So it's a left shift by 3 which would then be 0000, but with a the not, would it become 1111?


Solution

  • 1 << 3 is not 0000, it's 1000. Complementing that yields 0111, which then you AND with 1010:

      1010
    & 0111
    ------
      0010