① c語言字元數組如何轉成16進制
#include<stdio.h>
#include<string.h>
#include<malloc.h>
intmain(void)
{
char*pKey="";
intn=strlen(pKey)/2,i;
char*Key=(char*)malloc(sizeof(char)*n);
for(i=0;i<n;++i)
{
sscanf(pKey+2*i,"%2X",Key+i);
}
for(i=0;i<n;++i)
{
printf("%#02hhX",Key[i]);
}
return0;
}
② c語言輸入一個字元串轉換為十六進制並輸出
#include<stdio.h>
#include<string.h>
intmain()
{
unsignedi,len;
intn=0;
charstr[99]="123342abcdAFB1H",str1[99],str2[99]="";
sscanf(str,"%[0-9^a-f^A-F]",str1);
len=strlen(str1);
while(strlen(str1)>1)
{
sscanf(str1,"%2s",str2);
if(strlen(str1)!=len)printf(",");
printf("0x%s",str2);
n++;
for(i=0;i<strlen(str1)-2;i++)
{
str1[i]=str1[i+2];
}
str1[strlen(str1)-2]='