69,369
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int c,n,c_temp;
FILE *fi,*fo;
void main() {
fi=fopen("a.eep","rb");
if (NULL==fi) {
printf("Can not open file a.eep!\n");
return;
}
fo=fopen("a.hex","w");
if (NULL==fo) {
fclose(fi);
printf("Can not open file a.hex!\n");
return;
}
n=0;
while (1) {
c=fgetc(fi);
if (EOF==c) break;
c_temp=c & 15;/*取得ch1的后4位*/
if(c_temp>=0 && c_temp<=9) c_temp=c_temp+'0';/*输出*/
else c_temp=c_temp+55;
fprintf(fo,"\n0x%c",c_temp);
c_temp=15;
c_temp&=c>>4;/*取得ch1的后前位*/
if(c_temp>=0 && c_temp<=9) c_temp=c_temp+48;/*输出*/
else c_temp=c_temp+55;
fprintf(fo,"%c ",c_temp);
}
fclose(fo);
fclose(fi);
}
#include <stdio.h>
int c,n;
FILE *fi,*fo;
void main() {
fi=fopen("a.eep","rb");
if (NULL==fi) {
printf("Can not open file a.eep!\n");
return;
}
fo=fopen("a.hex","w");
if (NULL==fo) {
fclose(fi);
printf("Can not open file a.hex!\n");
return;
}
n=0;
while (1) {
c=fgetc(fi);
if (EOF==c) break;
n++;
if (1==n) fprintf(fo, "0x%02X",c);
else {
if (1==n%16) fprintf(fo,"\n0x%02X",c);
else fprintf(fo, ",0x%02X",c);
}
}
fclose(fo);
fclose(fi);
}