Bit field 2026-11-05
A bit field assigns a selected group of bits within a stored value to a particular component or meaning. For a contiguous field, specify its width , starting position counted from the least significant bit, and interpretation. In a pixel format, separate bit fields can hold red, green and blue component codes. The Linux frame-buffer interface describes such fields with explicit offset and length members.[ref]
For a nonnegative integer word , the unsigned value of the field is
In a language with the usual unsigned bitwise operations, this corresponds to shifting right by and applying bitwise AND with .
For an original eight-bit example, let , written 0xB5 or binary 10110101. Select three bits beginning at position 4, so the field consists of bits 6–4. Extraction gives
The field's bits are 011. To replace them by value 6, clear the field with mask 0x70, then insert 6 << 4. Restricted to eight-bit words, the calculation is
The other five bits are unchanged. The range specifies what fits in an unsigned field.
A language-level bit-field declaration is a related abstraction, but its physical placement follows that language and implementation. In the C programming language, unsigned int code : 3; declares a three-bit field; C11 leaves allocation order within a storage unit implementation-defined and the storage unit's alignment unspecified.[ref] Such a declaration alone therefore does not specify a portable external byte sequence. An explicit layout must also state the relevant endianness and storage rules.
Bit parallelism Created 2026-10-20 Updated 2026-11-05
Bit parallelism represents many Boolean states in the bits of a machine word and updates them together with bitwise operations. For example, if a bit at position records whether sum is reachable, adding an item of weight updates the state mask to mask | (mask << w), retaining old sums and adding shifted ones. A fixed-width operation processes up to the word width in parallel. An arbitrary-precision integer spanning many words still costs time proportional to the affected storage; using one language-level integer does not make every operation constant-time.
Bitwise operation Created 2026-10-20 Updated 2026-11-05
A bitwise operation applies a Boolean operation separately to corresponding positions of binary representations. For four-bit values 1010 and 1100, AND gives 1000, OR gives 1110, and exclusive or gives 0110. Bit shifts move positions, while bitwise complement reverses each bit. The representation width and signedness matter: fixed-width machine arithmetic and unbounded integers need not interpret leading bits alike. These operations are useful for compact sets, flags and bit parallelism. They differ from logical operations that test the truth of entire operands.[ref]
Packed pixel format 2026-11-05
A packed pixel format stores the component fields or index for each pixel together in a single image plane, with successive pixels following one another in that plane. A planar pixel format instead separates component or bit planes. Packed does not necessarily mean one byte per pixel or the absence of row padding: the Linux frame-buffer API explicitly permits end-of-row padding in its packed storage type.[ref]
Consider an original 16-bit encoding with 4-bit fields in the order red, green, blue, alpha from most significant to least significant:
The bit fields for give . Extracting components by integer arithmetic gives
The same extraction can be implemented with bitwise operations. Declaring endianness is a separate step: this word occupies successive bytes C5 A3 in little-endian storage, and A3 C5 in big-endian storage. A component order in a word does not by itself specify the byte sequence.
If a row contains 100 of these two-byte pixels, its active data occupy 200 bytes. With framebuffer stride 208 bytes, the next row begins 208 bytes later, leaving eight padding bytes. A pixel-buffer consumer therefore needs the exact pixel format, dimensions and framebuffer stride, as well as any alpha channel convention and color space.
Submask enumeration Created 2026-10-20 Updated 2026-11-05
A submask of a bit mask has no set bits outside . Start with and repeatedly replace a positive by
Process each positive before this update and stop when it becomes zero. To include the empty submask, process zero once and stop before updating it; otherwise the update can return to .
Subtracting one clears the lowest set bit and sets the lower positions. The bitwise AND with removes forbidden positions, producing the largest permitted submask strictly below the previous one. This proves decreasing order, no duplicates and no skipped submask.
For , the order is . A bit mask with set bits has submasks, because each allowed position is independently selected or omitted. Enumeration therefore takes updates under constant-cost bitwise operations; has only the empty submask.