自己写的垃圾程序,仅仅表现为能用,错误处理和代码优化暂时都抛弃了.如果用python,应当快多了.先贴出c的,里面的gcc4_debug.h里面只用到ERRX()
可以自己在程序开头定义一个.
编译: gcc 即可.
#include "/dvr/debug/gcc4_debug.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int itoa(int a, char *s, int n)
{ int i;
for(i = 0; i < n; i++, s++)
{
if((a & (1 << i)) != 0)
*s = '1';
else
*s = '0';
}
return 0;
}
int convert(unsigned char *buf, int size)
{
unsigned char ss[16][2][8];
unsigned char st[4][8][8];
int i,j,k;
int m;
if(size%2 != 0)
{
printf("size is %d\n", size);
ERRX(size is not a even
}
for(i = 0; i < 16; i++)
for(j = 0; j < 2; j++)
for(k = 0; k < 8; k++)
{
if((*(buf+ i*2 + j) & ( 1 << k)) != 0)
ss[i][j][7 - k] = 1;
else
ss[i][j][7 - k] = 0;
}
for(i = 0; i < 8; i ++)
for(j = 0; j < 8; j++)
{
st[0][i][j] = ss[j][0][i];
st[1][i][j] = ss[j][1][i];
st[2][i][j] = ss[8+j][0][i];
st[3][i][j] = ss[8+j][1][i];
}
for(i = 0; i < 4; i++)
for(j = 0; j < 8; j++)
{
m = 0;
for(k = 0; k < 8; k++)
if(st[i][j][k] != 0)
m |= st[i][j][k] << k;
*(buf++) = m;
}
}
int main()
{
FILE *fp1;
FILE *fp2;
char buf[32];
int bytes;
int i;
if((fp1 = fopen("./HZK16", "rb")) == NULL)
ERRX(fopen hzk16 error);
if((fp2 = fopen("./HZK16_H", "wb")) == NULL)
ERRX(fopen hzk16_h error);
while(1)
{
memset(buf, 0, 32);
bytes = fread(buf, 1,32, fp1);
if(bytes == 0)
break;
convert(buf, bytes); fwrite(buf, 1,bytes, fp2);
}
fclose(fp2);
fclose(fp1);
}
|
阅读(2141) | 评论(0) | 转发(0) |