diive.get_encoded_value_series

diive.get_encoded_value_series(int_series, bit_start, bit_end, gain=1, base=2, n_bits=8)[source]

Convert a subrange of bits from an integer series to floats with an optional gain applied.

Can be used to extract additional variables from binary values that were stored as integers.

For example, using series [250, 250, 250] first converts the integers to their binary representation (‘11111010’, without the leading ‘0b’), then adds leading zeros to fulfill the number of bits (n_bits=8, yields ‘11111010’, i.e., still the same because already 8 digits), then extracts the required bit subrange (‘1010’ for bit_start=4 and bit_end=8), then converts the subrange to integer representation (10) and then applies gain (in this example 6.25) to get the final values of 62.5. The final series is [62.5, 62.5, 62.5].

Background: Some measurements are stored as binary values that were converted to integers for practical reasons. For example, in the binary value ‘10110001 00101110’ (2 Bytes) each bit can represent a flag that is raised when certain conditions are met. Sometimes it is necessary to extract multiple specific bits from such binary values and convert them to a decimal representation for further processing.

Parameters:
  • int_series (Series) – Series of integer values from which to extract bits.

  • bit_start (int) – The starting index of the bit subrange (inclusive).

  • bit_end (int) – The ending index of the bit subrange (exclusive).

  • gain (float) – A gain factor to apply to the converted value (default is 1).

  • base (int) – The base of the integer (default is 2, binary).

  • n_bits (int) – The total number of bits in the integer (default is 8).

Return type:

Series

Returns:

Series of the converted and scaled values. Missing values stay NaN.

See also

get_encoded_value_from_int : Extract bits from a single integer value.

Example

See examples/io/io_extract.py for complete examples.