33,311
社区成员
发帖
与我相关
我的任务
分享
#include <conio.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
char cHex, chH, chL;
printf("Input hex val (Q to quit)!\n");
do
{
cHex = _getch();
chH='?', chL='?';
#define _Hex2Oct(x) chH = ((x)/8)+'0'; chL = ((x)%8)+'0';
if(cHex >= 'a' && cHex <= 'f')
{
_Hex2Oct(cHex - 'a' + 10);
}
else if(cHex >= 'A' && cHex <= 'F')
{
_Hex2Oct(cHex - 'A' + 10);
}
else if(cHex >= '0' && cHex <= '9')
{
_Hex2Oct(cHex - '0');
}
else
{
//unexpected
}
printf("%c=%c%c\n", cHex, chH, chL);
}while(cHex != 'Q' && cHex != 'q');
return 0;
}