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.
我有一个 .bin 文件,其中的像素数据以 4 位格式存储(即每个像素为 4 位)。如何将数据作为 4 位读入 C 程序。Char 以 8 位块的形式读取它,所以如果我有一个指向文件开头的指针并递增它,它会跳过一个像素。
我不知道有任何处理器允许您以小于一个字节的增量从文件中读取(尽管在某些处理器上字节中的位数会有所不同),并且 C++ 中不支持读取块小于一个字节的大小。假设一个字节中有 8 位,您将需要读取一个字节,然后将其分成两个像素。
如果您的读取返回 unsigned char c,那么
sometype pixel1 = c >> 4; sometype pixel2 = c & 0xf;