Ad space (banner)
๐ŸนGo Lessons
Lesson 54 / 68

Bitwise Operators (AND, OR, XOR, shifts)

In this lesson you will learn the basics of bitwise operators in Go, and understand what it means to work with a number bit by bit. This is for anyone searching for "Go bitwise operators how to use".

Bitwise operations 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 bitwise operations remain genuinely useful in embedded devices with limited memory and in implementing network protocols.

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

๐Ÿงช This site can't compile or run Go 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)