Expand description
Signal bit coding — the two bit-numbering systems of the DBC format.
DBC files number bits within the payload per byte, LSB-first: bit b
lives in byte b / 8 at in-byte mask 1 << (b % 8). That numbering is
the same for both byte orders; what differs is which bit start_bit
names and the direction of travel:
§Intel (little-endian, @1)
start_bit names the least significant bit of the signal; the value
is spread over the following bit_length bits, ascending, straight
through byte boundaries — a plain LSB-first linear field.
§Motorola (big-endian, @0)
start_bit names the most significant bit of the signal, in the
classic “sawtooth” numbering: extraction descends within each byte
(MSB → LSB), then jumps from bit 0 of one byte to bit 7 of the next
(+15 in DBC numbering — the sawtooth). This reproduces exactly what
Vector CANdb++, cantools, and the socketcan-cib tools do for @0
signals, including the famous layouts that straddle three bytes.
Bits falling outside the buffer read as 0 on extraction
(extract_raw is total); insertion reports the bytes it needs
(max_bit_position → crate::DbcError::BufferTooShort).
Functions§
- extract_
raw - Extracts
bit_lengthraw bits laid out perbyte_order, MSB-aligned into the low bits of the result. - insert_
raw - Inserts
value’s lowbit_lengthbits perbyte_order, the exact inverse ofextract_raw. - max_
bit_ position - The highest DBC bit number the signal layout touches.
- sign_
extend - Sign-extends
raw(the lowbit_lengthbits) toi64two’s complement.