Tag Archives: xor

Perform set operations on enumerable lists in C#

To demonstrate set operations, this example creates two lists of Person objects. The Person class implements IEquatable. The code then uses the following code to display the lists and their intersection, union, difference, and exclusive or (xor). // Display the … Continue reading

Posted in mathematics | Tagged , , , , , , , , , , , , | Leave a comment

Use bit operations in C#

C# defines several operators that perform bit operations. As you may be able to guess from the names, these operators manipulate the bits in an integer value. They operate on the value’s bits separately so they are sometimes called “bitwise … Continue reading

Posted in calculations, mathematics, variables | Tagged , , , , , , , , , , , , , | Leave a comment

Use XOR to swap two numbers in C#

Note that I don’t recommend this technique for swapping numbers. It’s mostly a clever trick that provides a lesson in the bitwise XOR operation. The code is much easier to understand if you just declare a temporary variable to make … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , | Leave a comment

Use set operators in C#

This example shows how you can add set operators to make working with sets slightly easier. The example Perform set operations in C# explains how to use the HashSet class to represent and manipulate sets. Unfortunately to manipulate the sets … Continue reading

Posted in algorithms, classes, mathematics | Tagged , , , , , , , , , , , , , , , , | Leave a comment