Ad space (banner)
๐ŸŽObjective-C Lessons
Lesson 54 / 68

Bitwise operations (AND, OR, XOR, shifts)

This lesson covers the basics of bitwise operations in Objective-C, with the aim of understanding how to manipulate a number bit by bit.

A bitwise operation treats a number as binary and calculates digit by digit. There are & (AND), | (OR), ^ (XOR), and << (left shift), used commonly for permission flags and low-level work.

The sample code shows the results of &, |, and ^ on the integers 12 and 10, plus a << 2, which shifts two bits left (multiplying by four). Thinking in binary makes each operation much clearer.

A common early stumble is confusing the logical &&/|| with the bitwise &/|. Branching uses &&/||; bit-level work uses &/|/^.

In professional work, bitwise operations are still used practically in embedded devices with limited memory and in bitmask-based state management.

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

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