Math Fundamentals18 sections · 814 units
Open in Course

Bitwise AND (&)

Both bits must be 1

The AND operator (&) compares two numbers bit by bit. For each position, the result has a 1 only if both input bits are 1. Otherwise, the result is 0.

Example: 12&1012 \& 10. In binary, 12=110012 = 1100 and 10=101010 = 1010. Comparing position by position: 1&1=11\&1=1, 1&0=01\&0=0, 0&1=00\&1=0, 0&0=00\&0=0. Result: 1000=81000 = 8.

You'll use AND to check if specific bits are set, or to clear bits by masking. It's one of the most common bit operations.