SoFunction
Updated on 2025-03-06

Introduction to the XOR operator of C#

 

Copy the codeThe code is as follows:

 int a = 5;
 int b = 30;
 (a^b);
 (); 
 

The output result is 27

This is because the binary of 5 is
0000 0101
The binary of 30 is
0001 1110

The XOR algorithm is to compare each bit of two binary numbers, if the same, it is 0, and if the difference is 1. So the formula should be listed:


0000 0101
0001 1110
--------------
0001 1011

I got 0001 1011. The decimal number represented by this binary is 27.