The BitField

The BitField

Referencing individual bit positions within a carrier type (using UInt16 as an example).

offset from the lsbit1514131211109876543210
most & least significantmsbitlsbit

The offset from the least significant bit gives the number of bit positions that must be shifted over to take the content occupying the lsb(it) and place it into the bit position given by that offset.

A bitfield may be formed of a single bit's position or formed of as many bit positions as exist within the carrier type, and any number of contiguous bit positions in between. The widest unsigned bits type is UInt128. So, the bitfield of maximal span is a field comprised of all 128 bit positions available where the carrier type is UInt128. For each of our available carrier types {UInt8, UInt16, UInt32, UInt64, UInt128}, there is an immediately associated bitfield of maximal span.

carrier typemaximal bitfield spancomment
UInt88prefer UInt16 unless app requires UInt8
UInt128128prefer UInt64 unless app requires UInt128

To represent a bitfield, any bitfield that

struct BitField{<:UBits} <: AbstractBitField
    maskof1s::U       # U is the `carrier` type
    maskof0s::U       #   an unsigned bits type