1 #include <stdio.h> 2 #define L 40 3 void jiaM(int * s,int * a,int *b,int *sy); 4 void jieM(int * a,int *b,int *sy); 5 int main() 6 { 7 int s[L]={1,1,1,0,0,1,0,1,0,0,0,1,0,0,1,1,0,0,1,1,1,1,0,0,1,0,1,0,0,0,1,0,0,1,1,0,0,1,1,0}; 8 // int s[L]={1,0,1,1,1,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0}; 9 int a[L/2],b[L/2],sy[L/2]; 10 jiaM(s,a,b,sy); 11 jieM(a,b,sy); 12 printf(" "); 13 return 0; 14 } 15 void jiaM(int * s,int * a,int *b,int *sy) 16 { 17 int i=0,j=1,k=0; 18 for(;i<L;i+=2,j+=2) 19 { 20 if(s[i]!=s[j]){sy[k++]=1;} 21 else{sy[k++]=0;} 22 } 23 24 for(i=0;i<L;i++) 25 {printf("%d",s[i]);} 26 printf("----´òÓ¡Ô´---- "); 27 28 for(i=0;i<L/2;i++) 29 {printf("%d ",sy[i]);} 30 printf("----´òÓ¡sy---- "); 31 32 int a1=0,b1=0; 33 for(k=0,i=0,j=1;i<L;i+=2,j+=2) 34 { 35 if(sy[k++]) 36 { 37 if(s[i]!=0) 38 { 39 b[b1++]=1; 40 }else 41 { 42 b[b1++]=0; 43 } 44 } 45 else 46 { 47 if(s[i]!=0) 48 { 49 a[a1++]=1; 50 }else 51 { 52 a[a1++]=0; 53 } 54 } 55 } 56 57 for(i=0;i<L/2;i++) 58 {if(a[i]==0||a[i]==1)printf("%d ",a[i]);} 59 printf("----´òÓ¡a---- "); 60 61 for(i=0;i<L/2;i++) 62 {if(b[i]==0||b[i]==1)printf("%d ",b[i]);} 63 printf("----´òÓ¡b---- "); 64 65 66 } 67 68 void jieM(int * a,int *b,int *sy) 69 { 70 int s[L],l=0,m=1,x=0,y=0,k,j; 71 for(k=0,j=0;k<L/2;k++,l+=2,m+=2) 72 { 73 if(sy[k]) 74 { 75 if(b[x++]) 76 { 77 s[l]=1; 78 s[m]=0; 79 } 80 else 81 { 82 s[l]=0; 83 s[m]=1; 84 } 85 } 86 else 87 { 88 if(a[y++]) 89 { 90 s[l]=1; 91 s[m]=1; 92 } 93 else 94 { 95 s[l]=0; 96 s[m]=0; 97 } 98 } 99 } 100 101 for(j=0;j<L;j++) 102 { 103 printf("%d",s[j]); 104 } 105 }
对二进制数据进行处理,生成索引(sy)和存储文件(a,b),其长度(源长度=sy+a+b,sy=a+b),索引很好推出,本来打算进行二进制压缩的,但没有想出好的办法。