Tag Archives: bit operations

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