c and c++ operators help -
Can anyone explain to me why the following results are B = 13?
int a, b, c; A = 1 | 2 | 4; B = 8; C = 2; B = A; B & amp; = ~ C; It is using binary manipultaors (assuming that ints are 1 byte, And two supplements for storage, etc.)
C = 2 means
a = 1 | 2 | 4
meansa = 00000001 or 00000010 or 00000100
, which is 00000111 or 7.
b = 8
meansb = 00001000
.c = 00000010
.
b | = A
deviceb = b | A
meansb = 00001000 or 00000111
, which is 00001111 or 15.~ c
meansnot c
, which is 11111101.
b & amp; = ~ C
meansb = b & amp; ~ C
, which meansB = 00001111 and 11111101
, which is 00001101 or 13.
Comments
Post a Comment