161 std::ostream& stream,
int length,
bool padEnd)
const {
164 if (lastIndex >=
bits_.size() && !padEnd) {
166 throw OutOfRange(__FILE__, __LINE__, procName);
169 const int nibbleCount =
static_cast<int>(ceil(
170 static_cast<double>(length) / 4.0));
172 std::vector<bool> bitRow;
176 bitRow.push_back(
bits_[i]);
180 int numPadBits = 4 * nibbleCount - length;
182 std::vector<bool> padBits(numPadBits, 0);
183 bitRow.insert(bitRow.begin(), padBits.begin(), padBits.end());
187 std::vector<uint8_t> Nibble;
188 for (
auto it = bitRow.begin(); it < bitRow.end(); it += 4) {
189 Nibble.push_back(std::accumulate(
190 it, it + 4, 0,[] (
int x,
int y) {
return (x << 1) + y;}));
194 for (
auto ui8 = Nibble.begin(); ui8 < Nibble.end(); ++ui8) {
195 stream << std::hex << (int) *ui8;