Home > Software design >  C Code Execution (C programming language)
C Code Execution (C programming language)

Time:10-21

What value will x have, after the following code gets executed?

char n1 = 0xF1; char n2 = 0x1F; char x = 0; x = n1 & n2;

I think it's 0, but I'm not exactly sure. What do you guys think?

CodePudding user response:

This performs the bitwise AND of each bit of the values.

To do that, you need to think of its binary form.

  0x1F   =>     0b0001 1111
& 0xF1   =>   & 0b1111 0001
------        -------------
  0x..   <=     0b.... ....

Fill in the blanks.

(There could be leading zeroes -- a char is not always 8 bits -- but it's irrelevant here because 0 AND 0 is 0.)

CodePudding user response:

The only stupid thing in this picture is all of the little minds who couldn't solve the problem without using a compiler, downvoting my question out of frustration and posting up their stupidity all over the Internet along with their incapacity, and this goes for all the users except @ikegami & Ian Abbott! If you can't solve it without a compiler, then it's best you shut up (your stupidity won't be so obvious that way)!

  • Related