c语言存储内容怎么输出为二进制,[C语言]把文件转成二进制输出 主要含汉字处理部分 - 代码贴 - BCCN...

#define _CRT_SECURE_NO_WARNINGS

#include

#include

void dec2yyy(int source,char* bin)

{

bin[8]='\0';

int j=7;

while(source>0)

{

bin[j]=source %2+0x30;

j--;

source/=2;

}

for(;j>=0;j--) bin[j]='0';

}

int main()

{

char buf[9]={'\0'};

FILE* pfile;

pfile=fopen("121.txt","rb+");

if(pfile==NULL)

{

printf("open file error!\n");

return 0;

}

char ch;

int col=0;

while(1)

{

ch=fgetc(pfile);

dec2yyy(ch & 0xff ,&buf[0]);

printf(" %8s ",&buf[0]);

col++;

if(col==8)

{

printf("\n");

col=0;

}

if(ch==EOF) break;

}

return 0;

}

/*

效果图例:

E:\ctest\t5\Debug>t5

00101111 00101111 00100000 01110100 00110101 00101110 01100011 01110000

01110000 00100000 00111010 00100000 10110110 10101000 11010010 11100101

10111111 11011000 11010110 11000110 11001100 10101000 11010011 10100110

11010011 11000011 10110011 11001100 11010000 11110010 10110101 11000100

11001000 11101011 10111111 11011010 10110101 11100011 10100001 10100011

00001101 00001010 00101111 00101111 00001101 00001010 00100011 01100100

01100101 01100110 01101001 01101110 01100101 00100000 01011111 01000011

01010010 01010100 01011111 01010011 01000101 01000011 01010101 01010010

01000101 01011111 01001110 01001111 01011111 01010111 01000001 01010010

01001110 01001001 01001110 01000111 01010011 00001101 00001010 00001101

00001010 00001101 00001010 00100011 01101001 01101110 01100011 01101100

01110101 01100100 01100101 00100000 00111100 01110011 01110100 01100100

01101001 01101111 00101110 01101000 00111110 00001101 00001010 00100011

01101001 01101110 01100011 01101100 01110101 01100100 01100101 00100000

00111100 01110011 01110100 01110010 01101001 01101110 01100111 00101110

01101000 00111110 00001101 00001010 00001101 00001010 01101001 01101110

01110100 00100000 01101101 01100001 01101001 01101110 00101000 00101001

00001101 00001010 01111011 00001101 00001010 00001001 01110000 01110010

01101001 01101110 01110100 01100110 00101000 00100010 01101000 01100101

01101100 01101100 01101111 00100000 01110111 01101111 01110010 01101100

01100100 00100001 01011100 01101110 00100010 00101001 00111011 00001101

00001010 00001101 00001010 00001101 00001010 00100000 00100000 00100000

00001101 00001010 00100000 00100000 00100000 00001101 00001010 00001001

01110010 01100101 01110100 01110101 01110010 01101110 00100000 00110000

00111011 00001101 00001010 01111101 11111111

E:\ctest\t5\Debug>

*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值