c and c++ operators help

c, c++

Solution

It is using binary manipultaors. (Assuming ints are 1 byte, and use Two's complement for storage, etc.)

`a = 1|2|4` means `a = 00000001 or 00000010 or 00000100`, which is 00000111, or 7. `b = 8` means `b = 00001000`. `c = 2` means `c = 00000010`. `b |= a` means `b = b | a` which means `b = 00001000 or 00000111`, which is 00001111, or 15. `~c` means `not c`, which is 11111101. `b &= ~c` means `b = b & ~c`, which means `b = 00001111 and 11111101`, which is 00001101, or 13.

Problem

can someone explain to me why the following results in b = 13? ``` int a, b, c; a = 1|2|4; b = 8; c = 2; b |= a; b&= ~c; ```

Original source