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.)  

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 device b = b | A means b = 00001000 or 00000111 , which is 00001111 or 15. ~ c means not c , which is 11111101.
b & amp; = ~ C means b = b & amp; ~ C , which means B = 00001111 and 11111101 , which is 00001101 or 13.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -