12 #ifndef hifi_BitVectorHelpers_h
13 #define hifi_BitVectorHelpers_h
15 #include "NumericalConstants.h"
17 int calcBitVectorSize(
int numBits) {
18 return ((numBits - 1) >> 3) + 1;
23 int writeBitVector(uint8_t* destinationBuffer,
int numBits,
const F& func) {
24 int totalBytes = calcBitVectorSize(numBits);
25 uint8_t* cursor = destinationBuffer;
29 for (
int i = 0; i < numBits; i++) {
33 if (++bit == BITS_IN_BYTE) {
44 assert((
int)(cursor - destinationBuffer) == totalBytes);
50 int readBitVector(
const uint8_t* sourceBuffer,
int numBits,
const F& func) {
51 int totalBytes = calcBitVectorSize(numBits);
52 const uint8_t* cursor = sourceBuffer;
55 for (
int i = 0; i < numBits; i++) {
56 bool value = (bool)(*cursor & (1 << bit));
58 if (++bit == BITS_IN_BYTE) {