int i の最下位ビットを char 型のバッファー buff に書き込み、ビット バッファー インデックスをインクリメントする writeBit メソッドがあります。私が持っているものが正しいかどうかはわかりませんが、どんな意見でも大歓迎です。
private:
char buff; // buffer
int num_bits; // num of bits written to buff
std::ostream& os_ref;
public:
// Skipping the constructor and ostream& for brevity
int writeBit(int i) {
// flush buffer if full
if(num_bits == 8)
flush();
// write least significant bit into the buffer at the current index.
int lb = i & 1;
buff = buff & num_bits; // not sure about this line
buff = lb;
num_bits++;
// return current index
return num_bits; // do I return nbits as current index?
}