12 static constexpr uint32_t MaxValue = (1 << BlockBits) - 1;
16 void set(uint32_t bitPosition, uint8_t value)
noexcept {
17 GAIA_ASSERT(bitPosition < (m_data.size() * 8));
18 GAIA_ASSERT(value <= MaxValue);
20 const uint32_t idxByte = bitPosition / 8;
21 const uint32_t idxBit = bitPosition % 8;
23 const uint32_t mask = ~(MaxValue << idxBit);
24 m_data[idxByte] = (uint8_t)(((uint32_t)m_data[idxByte] & mask) | ((uint32_t)value << idxBit));
26 const bool overlaps = idxBit + BlockBits > 8;
29 const uint32_t shift2 = 8U - idxBit;
30 const uint32_t mask2 = ~(MaxValue >> shift2);
31 m_data[idxByte + 1] = (uint8_t)(((uint32_t)m_data[idxByte + 1] & mask2) | ((uint32_t)value >> shift2));
35 uint8_t get(uint32_t bitPosition)
const noexcept {
36 GAIA_ASSERT(bitPosition < (m_data.size() * 8));
38 const uint32_t idxByte = bitPosition / 8;
39 const uint32_t idxBit = bitPosition % 8;
41 const uint8_t byte1 = (m_data[idxByte] >> idxBit) & MaxValue;
43 const bool overlaps = idxBit + BlockBits > 8;
46 const uint32_t shift2 = uint8_t(8U - idxBit);
47 const uint32_t mask2 = MaxValue >> shift2;
48 const uint8_t byte2 = uint8_t(((uint32_t)m_data[idxByte + 1] & mask2) << shift2);