我有一个 writeBit 方法,它应该将 int i 的最低有效位写入 char 类型的缓冲区缓冲区,然后增加位缓冲区索引。我不确定我所拥有的是否正确,感谢任何输入。
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?
}