* @brief Read up to 16 bits from two bytes. * * This function reads a packed N-bit field from two bytes in memory. The stored value must exist * within the two bytes, but can start at an arbitrary bit offset and span the two bytes in memory. * * @param bitcount The number of bits to read. * @param bitoffset The bit offset to read from, between 0 and 7. * @param[in,out]
| 476 | * @return The read value. |
| 477 | */ |
| 478 | static inline unsigned int read_bits( |
| 479 | unsigned int bitcount, |
| 480 | unsigned int bitoffset, |
| 481 | const uint8_t* ptr |
| 482 | ) { |
| 483 | unsigned int mask = (1 << bitcount) - 1; |
| 484 | ptr += bitoffset >> 3; |
| 485 | bitoffset &= 7; |
| 486 | unsigned int value = ptr[0] | (ptr[1] << 8); |
| 487 | value >>= bitoffset; |
| 488 | value &= mask; |
| 489 | return value; |
| 490 | } |
| 491 | |
| 492 | /* See header for documentation. */ |
| 493 | void encode_ise( |