代码 (注意:字母全小写)
#include <iostream>
using namespace std;
#define byte unsigned char
byte hex2byte(char hexstr[]);
int main()
{
char hex[3] = "67";
cout << int(hex2byte(hex));
}
byte hex2byte(char hexstr[])
{
byte h = hexstr[0];
byte l = hexstr[1];
if (isalpha(h))
h = h - 'a' + 10;
else
h = h - '0';
if (isalpha(l))
l = l - 'a' + 10;
else
l = l - '0';
return h * 16 + l;
}
网友评论