10#ifndef SEMF_UTILS_PROCESSING_BITSETUTILITY_H_
11#define SEMF_UTILS_PROCESSING_BITSETUTILITY_H_
43 static std::bitset<N>
createBitset(
const uint8_t data[],
size_t dataSize,
size_t firstBit);
55 static size_t insertBitsetInBuffer(std::bitset<N> bitset, uint8_t buffer[],
size_t bufferSize,
size_t firstBit);
61 return bits.count() % 2;
67 std::bitset<N> bitset;
69 for (
size_t i = 0; (i < N) && (((firstBit + i) / 8) < dataSize); i++)
71 bitset.set(i, data[(firstBit + i) / 8] & (1 << ((firstBit + i) % 8)));
78static size_t insertBitsetInBuffer(std::bitset<N> bitset, uint8_t buffer[],
size_t bufferSize,
size_t firstBit)
82 for (; (i < N) && (((firstBit + i) / 8) < bufferSize); i++)
85 buffer[(firstBit + i) / 8] |=
static_cast<uint8_t
>((1 << ((firstBit + i) % 8)));
88 buffer[(firstBit + i) / 8] &=
static_cast<uint8_t
>(~(1 << ((firstBit + i) % 8)));
Useful helper functions for handeling bitsets.
static std::bitset< N > createBitset(const uint8_t data[], size_t dataSize, size_t firstBit)
Copies a part of an array into a bitset.
static size_t insertBitsetInBuffer(std::bitset< N > bitset, uint8_t buffer[], size_t bufferSize, size_t firstBit)
Insert a bitset in a array.
static bool parityIsOdd(std::bitset< N > bits)
Returns the parity of bits in a bitset.
static size_t insertBitsetInBuffer(std::bitset< N > bitset, uint8_t buffer[], size_t bufferSize, size_t firstBit)