Having error when trying to update bit value to "0" using left shift

24 views Asked by At

I'm trying to change the value of x from 5 to 7 to 6 using these bitwise operators. However, the second time where it says x = (x|(0 << 0)); yields no change and is ignored when I trace it.

No errors. Any tips?

int main() {
    unsigned short x = 5;
    
    x = (x|(1 << 1));
    printf("%hd\n", x);
    x = (x|(0 << 0));
    printf("%d\n", x);
  return 0;
}
0

There are 0 answers