Ad space (banner)
#๏ธโƒฃC# Lessons
Lesson 54 / 68

Bitwise Operators (AND, OR, XOR, shifts)

In this lesson you will learn the basics of bitwise operators in C# (AND, OR, XOR, shifts), and understand what it means to work with a number bit by bit. This is for anyone searching for "C# bitwise operators how to use".

Bitwise operators treat a number as binary and calculate bit by bit. There is & (AND), | (OR), ^ (XOR), and << (left shift), and they show up in permission flags and low-level work.

The sample code applies &, |, and ^ to the integers 12 and 10, and shifts left by two bits with a << 2, which multiplies by four. Thinking in binary makes each operation much easier to follow.

A common stumbling block for beginners is confusing the logical operators &&/|| with the bitwise &/|. Use &&/|| for conditionals and &/|/^ for bit-level work.

In real-world development, they do not come up much in everyday application work, but they are valuable knowledge for performance-critical code.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run C# directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)