سؤال

nt main()
{
    cout << ('a'^'b');
}

when i wrote this simple code(in C++) program giving the "3" output. but it must be "1". do you know why? is there problem with the xor operator??

هل كانت مفيدة؟

المحلول

There is no problem with XOR and the result of 3 is correct.

   'a' XOR 'b'
-> 0x61 XOR 0x62          (hex, per ASCII)
-> 01100001 XOR 01100010  (binary)
-> 00000011               (only these bits differ)
-> 3                      (decimal)

Consider the following, which is 1 - why?

'`' ^ 'a'
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top