#define CODESIZE 65536
int datFile, i;
unsigned char binDat[CODESIZE];
unsigned char datDat[(CODESIZE*2)];
char binTmp;
datFile=open("a.dat",O_RDONLY|O_BINARY);
read(datFile, datDat, (CODESIZE*2)); //读Upload 出来的文件(删除了0D 0A)
close(datFile);
for(i=0; i<CODESIZE ;i++)
{
binTmp = datDat[2*i];
if(binTmp>=48 && binTmp<97)
binDat[i] = (binTmp-48)*16;
else
binDat[i] = (binTmp-87)*16;
binTmp = datDat[2*i+1];
if(binTmp>=48 && binTmp<97)
binDat[i] += binTmp-48;
else
binDat[i] += binTmp-87;
}
datFile=open("b.bin",O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IWRITE|S_IREAD);
write(datFile, binDat, CODESIZE); //写Bin 文件
close(datFile);
|