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

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

问题描述

我知道下面的功能:

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

这只能由字节读取字节,我的目标是能够在一次读取12位,然后带他们到一个数组。任何帮助或指针将不胜AP preciated!

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变量,并写有),然后使用位运算符>>和&lt;&LT;逐位读位。在这里阅读更多:<一href=\"http://www.cprogramming.com/tutorial/bitwise_operators.html\">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天全站免登陆