src.bluetooth_sig.gatt.characteristics.utils.bit_field_utils¶
Bit field manipulation and flag handling utilities.
Classes¶
Name | Description |
|---|---|
Utility class for bit field manipulation and flag handling. |
|
Common bit position constants for flag manipulation. |
Module Contents¶
- class src.bluetooth_sig.gatt.characteristics.utils.bit_field_utils.BitFieldUtils¶
Utility class for bit field manipulation and flag handling.
- static calculate_parity(value: int) int¶
Calculate the parity (even/odd) of set bits.
Returns 0 for even, 1 for odd.
- static compare_bit_fields(value1: int, value2: int, start_bit: int, num_bits: int) int¶
Compare bit fields between two values.
Returns -1, 0, or 1.
- static copy_bit_field(source: int, dest: int, source_start: int, dest_start: int, num_bits: int) int¶
Copy a bit field from source to destination.
- static create_bitmask(start_bit: int, num_bits: int) int¶
Create a bitmask for a specific bit field range.
- static extract_bit_field(value: int, start_bit: int, num_bits: int) int¶
Extract a bit field from an integer value.
- static extract_bit_field_from_mask(value: int, mask: int, shift: int) int¶
Extract a bit field using a mask and shift amount.
- Parameters:
value – The value to extract from
mask – The base mask (e.g., 0x0F for 4 bits)
shift – How many bits to shift the mask left
- Returns:
The extracted bit field value
- static find_first_set_bit(value: int) int | None¶
Find the position of the first (least significant) set bit.
- static find_last_set_bit(value: int) int | None¶
Find the position of the last (most significant) set bit.
- static get_bit_positions(value: int) list[int]¶
Get a list of positions of all set bits in the value.
- static merge_bit_fields(*fields: tuple[int, int, int]) int¶
Merge multiple bit fields into a single value.
- Parameters:
fields – Tuples of (field_value, start_bit, num_bits)
- static reverse_bits(value: int, bit_width: int = DEFAULT_BIT_WIDTH) int¶
Reverse the bits in a value within the specified bit width.
- static rotate_left(value: int, positions: int, bit_width: int = DEFAULT_BIT_WIDTH) int¶
Rotate bits left by the specified number of positions.
- static rotate_right(value: int, positions: int, bit_width: int = DEFAULT_BIT_WIDTH) int¶
Rotate bits right by the specified number of positions.
- static set_bit_field(value: int, field_value: int, start_bit: int, num_bits: int) int¶
Set a bit field in an integer value.
- static shift_bit_field_left(value: int, start_bit: int, num_bits: int, shift_amount: int) int¶
Shift a bit field left within the value.
- static shift_bit_field_right(value: int, start_bit: int, num_bits: int, shift_amount: int) int¶
Shift a bit field right within the value.
- static split_bit_field(value: int, *field_specs: tuple[int, int]) list[int]¶
Split a value into multiple bit fields.
- Parameters:
value – The value to split
field_specs – Tuples of (start_bit, num_bits) for each field
- Returns:
List of extracted field values
- static validate_bit_field_range(start_bit: int, num_bits: int, total_bits: int = DEFAULT_BIT_WIDTH) bool¶
Validate that a bit field range is within bounds.
- DEFAULT_BIT_WIDTH = 32¶
- SINGLE_BIT_MASK = 1¶