flexfloat.ListBoolBitArray

class flexfloat.ListBoolBitArray(bits=None)[source]

A bit array class that encapsulates a list of booleans with utility methods.

This implementation uses a list of boolean values to represent the bits, allowing for dynamic resizing and easy manipulation of individual bits.

__init__(bits=None)[source]

Initializes a ListBoolBitArray.

Parameters:

bits (list[bool] | None, optional) – Initial list of boolean values. Defaults to empty list.

classmethod from_bits(bits=None)[source]

Creates a BitArray from a list of boolean values.

Parameters:

bits (list[bool] | None, optional) – List of boolean values. Defaults to None, which creates an empty BitArray.

Returns:

A BitArray created from the bits.

Return type:

ListBoolBitArray

classmethod zeros(length)[source]

Creates a BitArray filled with zeros.

Parameters:

length (int) – The length of the bit array.

Returns:

A BitArray filled with False values.

Return type:

ListBoolBitArray

classmethod ones(length)[source]

Creates a BitArray filled with ones.

Parameters:

length (int) – The length of the bit array.

Returns:

A BitArray filled with True values.

Return type:

ListBoolBitArray

to_int()[source]

Converts the bit array to an unsigned integer (LSB-first).

Returns:

The integer represented by the bit array.

Return type:

int

copy()[source]

Creates a copy of the bit array.

Returns:

A new BitArray with the same bits.

Return type:

ListBoolBitArray

to_float()[source]

Converts a 64-bit array to a floating-point number (LSB-first).

Returns:

The floating-point number represented by the bit array.

Return type:

float

Raises:

AssertionError – If the bit array is not 64 bits long.

__len__()[source]

Returns the length of the bit array.

Returns:

The number of bits in the array.

Return type:

int

__getitem__(index: int) bool[source]
__getitem__(index: slice) ListBoolBitArray

Get a bit or a slice of bits as a new ListBoolBitArray.

__setitem__(index: int, value: bool) None[source]
__setitem__(index: slice, value: BitArray | list[bool]) None

Sets an item or slice in the bit array.

Parameters:
  • index (int or slice) – The index or slice to set.

  • value (bool or list[bool] or BitArray) – The value(s) to assign.

Raises:

TypeError – If value type does not match index type.

__iter__()[source]

Iterates over the bits in the array.

Yields:

bool – The next bit in the array.

__add__(other)[source]

Concatenates two bit arrays.

Parameters:

other (BitArray or list[bool]) – The other bit array or list to concatenate.

Returns:

The concatenated bit array.

Return type:

ListBoolBitArray

__radd__(other)[source]

Reverse concatenation with a list.

Parameters:

other (list[bool]) – The list to concatenate before this bit array.

Returns:

The concatenated bit array.

Return type:

ListBoolBitArray

__repr__()[source]

Returns a string representation of the BitArray.

Returns:

String representation of the BitArray.

Return type:

str