/ˈbɪtˌwaɪz ˌɒpəˈreɪʃənz/
noun — "manipulating individual bits in data."
Bitwise Operations are low-level computational operations that act directly on the individual bits of binary numbers or data structures. They are fundamental to systems programming, embedded systems, encryption, compression algorithms, and performance-critical applications because they provide efficient, deterministic manipulation of data at the bit level. Common operations include AND, OR, XOR, NOT, bit shifts (left and right), and rotations.
Technically, bitwise operations treat data as a sequence of bits rather than as numeric values. Each operation applies a Boolean function independently to corresponding bits of one or more operands. For example, the AND operation sets a bit to 1 only if both corresponding bits are 1. Bit shifts move all bits in a binary number left or right by a specified count, introducing zeros on one end and optionally discarding bits on the other. Rotations cyclically shift bits without loss, which is often used in cryptography and hash functions.
Operationally, bitwise operations are employed in masking, flag manipulation, performance optimization, and protocol encoding. For example, a single byte can encode multiple Boolean flags, with each bit representing a different feature. Masks and bitwise AND/OR/XOR are used to set, clear, or toggle these flags efficiently. In embedded systems, bitwise operations control hardware registers, set I/O pins, and configure peripherals with minimal overhead. In cryptography, they form the core of algorithms such as AES, SHA, and many stream ciphers.
Example of common bitwise operations in C:
unsigned char flags = 0b00001101;
// Set bit 2
flags |= 0b00000100
// Clear bit 0
flags &= 0b11111110
// Toggle bit 3
flags ^= 0b00001000
// Check if bit 2 is set
if (flags & 0b00000100) { ... }
In practice, bitwise operations optimize memory usage, accelerate arithmetic operations, implement encryption and compression, and facilitate low-level communication protocols. Understanding the precise behavior of these operations is critical for writing efficient, correct, and secure system-level code.
Conceptually, bitwise operations are like adjusting individual switches on a control panel, where each switch represents a distinct feature or value, allowing fine-grained control without affecting other switches.
See Embedded Systems, Encryption, LSB, Masking, Data Manipulation.