Ask a questionAsk a question
 

AnswerC# Logical XOR

  • Saturday, November 07, 2009 5:10 PMrecherche Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Guys,

    Can you explain what this statement: Console.WriteLine("0x{0:x}", 0xf8 ^ 0x3f); does?

     

    Thanks

    • Edited byrecherche Saturday, November 07, 2009 5:10 PMtypo
    • Edited byrecherche Saturday, November 07, 2009 5:13 PMtypo
    •  

Answers

  • Saturday, November 07, 2009 5:18 PMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi.

    See this link

    http://msdn.microsoft.com/en-us/library/zkacc7k1.aspx
    it says that

    Binary ^ operators are predefined for the integral types and bool. For integral types, ^ computes the bitwise exclusive-OR of its operands. For bool operands, ^ computes the logical exclusive-or of its operands; that is, the result is true if and only if exactly one of its operands is true.

    and explanation of example.

    0xf8 is hex and in binary it is 11111000
    0x3f is hex and in binary it is 00111111
    and the result is
    0xc7 is hex and in binary it is 11000111

    Compare the value by bits.

    Ex:

    1 ^ 0 result is 1
    1^1 result is 0

    As you can see if only one of bits is true the result is true otherwise false.

    • Marked As Answer byrecherche Saturday, November 07, 2009 5:35 PM
    •  

All Replies

  • Saturday, November 07, 2009 5:18 PMTamer OzMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi.

    See this link

    http://msdn.microsoft.com/en-us/library/zkacc7k1.aspx
    it says that

    Binary ^ operators are predefined for the integral types and bool. For integral types, ^ computes the bitwise exclusive-OR of its operands. For bool operands, ^ computes the logical exclusive-or of its operands; that is, the result is true if and only if exactly one of its operands is true.

    and explanation of example.

    0xf8 is hex and in binary it is 11111000
    0x3f is hex and in binary it is 00111111
    and the result is
    0xc7 is hex and in binary it is 11000111

    Compare the value by bits.

    Ex:

    1 ^ 0 result is 1
    1^1 result is 0

    As you can see if only one of bits is true the result is true otherwise false.

    • Marked As Answer byrecherche Saturday, November 07, 2009 5:35 PM
    •  
  • Saturday, November 07, 2009 5:35 PMrecherche Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks