声明:extern void bintohex(int *binary, char *hex);
int str[]={1,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1};
char *hex =(char *)malloc(sizeof( char));
int i=0,k=0;
while (str[i]==0 || str[i]==1 ){k++; i++;}//计算长度
bintohex(str,hex);
for (int t=0; t< k/4; t++)printf("%c",hex[t]);
void bintohex(int *binary, char *hex )
{
int i=0,j=3,k=0,s = 0;
//计算整形数组的长度
while (binary [i]==0 || binary[i]==1 ){k++; i++;}
//char *hex =(char *)malloc(sizeof(char));
int *b = (int *)malloc(strlen(hex)* sizeof(int ));
//把二进制的每个字符转换成十六进制
for (i = 0; i < k/4; i++)
{
b[i]= binary[j]+binary [j-1]*2+binary[j-2]*4+ binary[j-3]
因篇幅问题不能全部显示,请点此查看更多更全内容