29 if (nBits > m_BitSize || m_BitPos > m_BitSize - nBits)
32 const uint32_t bit_pos = m_BitPos % 8;
33 size_t byte_pos = m_BitPos / 8;
34 uint8_t current_byte = m_pData[byte_pos];
37 uint32_t bit = (current_byte & (1 << (7 - bit_pos))) ? 1 : 0;
42 uint32_t bit_left = nBits;
45 uint32_t bits_readable = 8 - bit_pos;
46 if (bits_readable >= bit_left) {
47 result = (current_byte & (0xff >> bit_pos)) >> (bits_readable - bit_left);
51 bit_left -= bits_readable;
52 result = (current_byte & ((1 << bits_readable) - 1)) << bit_left;
55 while (bit_left >= 8) {
57 result |= m_pData[byte_pos++] << bit_left;
60 result |= m_pData[byte_pos] >> (8 - bit_left);