Appends the given sequence of bits to the given byte-based bit buffer, increasing the bit length.
| 182 | |
| 183 | // Appends the given sequence of bits to the given byte-based bit buffer, increasing the bit length. |
| 184 | testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen) { |
| 185 | assert(0 <= numBits && numBits <= 16 && (unsigned long)val >> numBits == 0); |
| 186 | for (int i = numBits - 1; i >= 0; i--, (*bitLen)++) |
| 187 | buffer[*bitLen >> 3] |= ((val >> i) & 1) << (7 - (*bitLen & 7)); |
| 188 | } |
| 189 | |
| 190 | |
| 191 |
no test coverage detected