get a twos-complement value from the first 'length' bits of a uint32_t With thanks to betaflight */
| 569 | With thanks to betaflight |
| 570 | */ |
| 571 | int32_t get_twos_complement(uint32_t raw, uint8_t length) |
| 572 | { |
| 573 | if (raw & ((int)1 << (length - 1))) { |
| 574 | return ((int32_t)raw) - ((int32_t)1 << length); |
| 575 | } |
| 576 | return raw; |
| 577 | } |