逐位读取二进制文件 [英] Reading a binary file bit by bit

查看:24
本文介绍了逐位读取二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道下面的函数:

size_t fread(void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file);

它只能逐字节读取,我的目标是能够一次读取 12 位,然后将它们放入一个数组中.任何帮助或指点将不胜感激!

It only reads byte by byte, my goal is to be able to read 12 bits at a time and then take them into an array. Any help or pointers would be greatly appreciated!

推荐答案

添加到第一个注释,你可以尝试一次读取一个字节(声明一个char变量并在那里写入),然后使用位运算符>>和<<一点一点地阅读.在此处阅读更多信息:http://www.cprogramming.com/tutorial/bitwise_operators.html

Adding to the first comment, you can try reading one byte at a time (declare a char variable and write there), and then use the bitwise operators >> and << to read bit by bit. Read more here: http://www.cprogramming.com/tutorial/bitwise_operators.html

这篇关于逐位读取二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆