VC 字符类型转换成整型显示,整型转换成字符型显示
我现在的一个问题就是要把 Uint a=123;转换成 Unsigned char的16进制的显示方式,如 7B,
另一方面,就是把字符型7B显示成 整型的123,求高手指教!!最好能提供例子
只是显示嘛
#include
#include
#include
#include
using namespace std;
////////////////////////////
const char* forprinthex(unsigned int i)
{
static char tmp[17];
sprintf(tmp, "%X", i);
return tmp;
}
const char* forprintnum(char* hex)
{
static char tmp[17];
unsigned int i;
sscanf(hex, "%X", &i);
sprintf(tmp, "%d", i);
return tmp;
}
///////////////////////////
int main()
{
unsigned int a = 123;
cout<< forprinthex(a)<char* p = "7B";
cout<< forprintnum(p)<system("pause");
return 0;
}。