Ad space (banner)
🔧C Lessons
Lesson 54 / 68

Bitwise Operators (AND, OR, XOR, shifts)

This lesson covers the basics of C's bitwise operators — AND, OR, XOR, and shifts — so you understand the idea of manipulating a number bit by bit. It's for anyone searching "C bitwise operator usage."

Bitwise operators treat a number as binary and compute bit by bit. There's & (AND), | (OR), ^ (XOR), and << (left shift), commonly used for things like managing permission flags and low-level operations.

The example shows the results of &, |, and ^ on the integers 12 and 10, plus the result of shifting a left by 2 bits with a << 2 (quadrupling it). Thinking about it in binary makes each operation's meaning much clearer.

A common early mistake is confusing the logical operators &&/|| with the bitwise operators &/|. Use &&/|| for conditionals, and &/|/^ for bit-level operations — a distinction worth being conscious of.

In real projects, bitwise operators are still put to genuinely practical use in embedded devices with limited memory, and in network protocol implementations.

📖 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)