包含缓冲区值的文件。前 16 位包含类型。接下来的 32 位给出了数据的长度。数据中的剩余值。
如何从16位中查找类型(查找是int还是char...)
我在这里陷入了我的思考过程。无法找到将位转换为类型的方法。
最佳答案
假设您有家庭作业:
You are given a file where the first bit encodes the type, the next 7 bits encode the length, and the rest is the data.
The types are encoded in the following way:
0
is for int1
is for charPrint the ints or chars separated by newlines.
您只需使用给定的信息即可!由于使用 1 位来对类型进行编码,因此有两种可能的类型。所以你只需阅读第一位,然后执行:
if (bit == 0) {
int *i = ...
}
else if (bit == 1) {
char *c = ...
}
关于c++ - 从缓冲区输入的位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54971680/