数据转换-位串字节数组
utils.c:
#include<stdio.h> #include<string.h> #include"utils.h" int Hex2Char(int fromi,char *toc) { if(fromi>=0&&fromi<=9) { *toc= fromi+'0'; } else if(fromi>=10&&fromi<=15) { *toc = fromi+'A'-10; } else { printf("error"); } return 0; } int Char2Hex(char fromc,int *toi) { if(fromc>='0'&& fromc<='9') { *toi= fromc-'0'; } else if(fromc>='A'&& fromc<='F') { *toi= fromc-'A'+10; } else { printf("error"); } return 0; } int ByteArr2BitStr(char *ba,char *bs) { int i,j,L,k,a; L = strlen(ba); for(j=0;j<L;j++) { Char2Hex(ba[j],&a); for(i=0;i<4;i++) { bs[3*(j+1)-i+j] = a%2+'0'; a=a/2; } } bs[4*L]='