汉字与十六进制互转,输入1汉字转十六进制,输入2十六进制转汉字
立即下载
资源介绍:
工程可在dev软件中打开,压缩包中带有exe文件,可在window下直接执行
#include
#include
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define MAX_NUM 100
int main() {
unsigned char hanzi[MAX_NUM] = {0};
unsigned char hex[MAX_NUM] = {0};//0xB0,0xAE,0xCE,0xD2,0xD6,0xD0,0xBB,0xAA
int i = 0;
int flag;
do
{
printf("汉字转十六进制输入1\n十六进制转汉字输入2\n请输入:");
scanf("%d",&flag);
if(flag == 1)
{
printf("请输入汉字:");
scanf("%s",&hanzi);
printf("输入汉字的十六进制为:");
for (i = 0; i < MAX_NUM; i++) {
if(hanzi[i] == '\0')
{
break;
}
printf("%02X ",hanzi[i]);
}
printf("\n");
}
else if(flag == 2)
{
printf("请输入十六进制的数:");
while (getchar() != '\n')
{
;
}
i = 0;
do{
scanf("%x",&hex[i]);
i++;
if(i >= MAX_NUM)
{
break;
}
}while(getchar()!='\n');//遇到换行时结束循环
printf("输入十六进制的汉字为:");
printf("%s\n",hex);
}
else
{
printf("输入错误,请重新输入1或2!!!\n");
}
}while(1);
return 0;
}