Skip to content

Word

busylight_core.word

Bitwise operations on a word of bits.

Classes

busylight_core.word.Word

Word(value=0, length=8)

A class representing a word of bits, with methods for bit manipulation.

Initialize a Word of length bits with the given value.

Source code in src/busylight_core/word.py
def __init__(self, value: int = 0, length: int = 8) -> None:
    """Initialize a Word of length bits with the given value."""
    if length <= 0 or length % 8 != 0:
        msg = "length must be a multiple of 8"
        raise ValueError(msg)

    self.initial_value = value
    self.length = length
    self.bits = array.array("B", [(value >> n) & 1 for n in self.range])
Attributes
busylight_core.word.Word.initial_value instance-attribute
initial_value = value
busylight_core.word.Word.length instance-attribute
length = length
busylight_core.word.Word.bits instance-attribute
bits = array('B', [value >> n & 1 for n in range])
busylight_core.word.Word.value property
value

Return the integer value of the word.

busylight_core.word.Word.range property
range

Return the range of bit offsets for this word.

busylight_core.word.Word.hex property
hex

Return a string hexadecimal representation of the word.

busylight_core.word.Word.bin property
bin

Return a string binary representation of the word.

Functions
busylight_core.word.Word.clear
clear()

Clear all bits in the word.

Source code in src/busylight_core/word.py
def clear(self) -> None:
    """Clear all bits in the word."""
    self.bits = array.array("B", [0] * self.length)

busylight_core.word.ReadOnlyBitField

ReadOnlyBitField(offset, width=1)

A class representing a read-only bit field within a word.

Initialize a bitfield with the given offset and width.

Source code in src/busylight_core/word.py
def __init__(self, offset: int, width: int = 1) -> None:
    """Initialize a bitfield with the given offset and width."""
    self.field = slice(offset, offset + width)
Attributes
busylight_core.word.ReadOnlyBitField.field instance-attribute
field = slice(offset, offset + width)

busylight_core.word.BitField

BitField(offset, width=1)

Bases: ReadOnlyBitField

A class representing a mutable bit field within a word.

Initialize a bitfield with the given offset and width.

Source code in src/busylight_core/word.py
def __init__(self, offset: int, width: int = 1) -> None:
    """Initialize a bitfield with the given offset and width."""
    self.field = slice(offset, offset + width)
Attributes
busylight_core.word.BitField.field instance-attribute
field = slice(offset, offset + width)