Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
包含缓冲区值的文件。前 16 位包含类型。接下来的 32 位给出了数据的长度。数据中的剩余值。
如何从 16 位中找到类型(查找它是 int 还是 char ...)
我在这里超级卡在我的过程中。无法找到将位转换为类型的方法。
假设你有家庭作业:
你得到一个文件,其中第一位编码类型,接下来的 7 位编码长度,其余的是数据。 类型按以下方式编码: 0是为 int 1是为 char 打印由换行符分隔的整数或字符。
你得到一个文件,其中第一位编码类型,接下来的 7 位编码长度,其余的是数据。
类型按以下方式编码:
0
1
打印由换行符分隔的整数或字符。
您只需使用给定的信息!由于 1 位用于编码类型,因此有两种可能的类型。因此,您只需阅读第一位,然后执行以下操作:
if (bit == 0) { int *i = ... } else if (bit == 1) { char *c = ... }