解决方法
像这样的东西? (不确定模板魔术是否在我的预期中起作用.我在C中生锈了.)
std::bitset bytesToBitset<int numBytes>(byte *data) { std::bitset<numBytes * CHAR_BIT> b; for(int i = 0; i < numBytes; ++i) { byte cur = data[i]; int offset = i * CHAR_BIT; for(int bit = 0; bit < CHAR_BIT; ++bit) { b[offset] = cur & 1; ++offset; // Move to next bit in b cur >>= 1; // Move to next bit in array } } return b; }