Return 8 bits from a bitstring staring from the nth bit. * * Precondition: NULL != s * n + 8 <= s->len; */
| 40 | * n + 8 <= s->len; |
| 41 | */ |
| 42 | static inline uint_fast8_t getByte(const bitstring *s, size_t n) { |
| 43 | simplicity_assert(8 <= s->len); |
| 44 | simplicity_assert(n <= s->len - 8); |
| 45 | size_t total_offset = s->offset + n; |
| 46 | if (total_offset % CHAR_BIT <= CHAR_BIT - 8) { |
| 47 | return (uint_fast8_t)(0xff & (s->arr[total_offset / CHAR_BIT] >> (CHAR_BIT - 8 - (total_offset % CHAR_BIT)))); |
| 48 | } else { |
| 49 | /* CHAR_BIT < total_offset % CHAR_BIT + 8 */ |
| 50 | return (uint_fast8_t)(0xff & (((1U * s->arr[total_offset / CHAR_BIT]) << (total_offset % CHAR_BIT - (CHAR_BIT - 8))) |
| 51 | | (s->arr[total_offset / CHAR_BIT + 1] >> (CHAR_BIT - (total_offset % CHAR_BIT - (CHAR_BIT - 8)))))); |
| 52 | } |
| 53 | } |
| 54 | #endif |
no outgoing calls
no test coverage detected