码迷,mamicode.com
首页 > 其他好文 > 详细

读取二进制转换为字符串

时间:2017-06-24 15:32:52      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:out   swa   file   wap   转换   print   color   inf   字符串   

#include<stdio.h> 
#include<stdlib.h>//为了使用exit() 
int swapInt32(int value)
{
    return ((value & 0x000000FF) << 24) |
        ((value & 0x0000FF00) << 8) |
        ((value & 0x00FF0000) >> 8) |
        ((value & 0xFF000000) >> 24) ;
}

int main()
{
    int a,b;
    FILE *outFp, *inFp;
    inFp=fopen("DMIMOLog.DAT","rb+");
    if(inFp==NULL){
        printf("open in file error!\n");
        return 0;
    }
    outFp=fopen("DMIMOLog.txt","w+");
    if(outFp==NULL){
        printf("open outFp file error!\n");
        return 0;
    }

    for(int i=0;i<8192*2;i++)
    {
        fread(&a,sizeof(int),1,inFp);
        b=swapInt32(a);
        //printf("%05x\r\n",b);
        fprintf(outFp,"%05x\r\n",b);
    }
    fclose(inFp);
    fclose(outFp);
    printf("finish\r\n");
}

 

读取二进制转换为字符串

标签:out   swa   file   wap   转换   print   color   inf   字符串   

原文地址:http://www.cnblogs.com/cheshl/p/7073367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!