这个和转2进制的原理一样,不过我这个程序可以很容易的拓展到n进制:
#include<iostream>
using namespace std;
void ToHex(char *buf,int x)
...{
char *pNum="0123456789ABCDEF";
char *t=buf;
for(;x;x/=16)...{
*t++=*(pNum+(x%16));
}
*t=0;
for(--t;buf<t;++buf,--t)...{
*buf^=*t;
*t^=*buf;
*buf^=*t;
}
}
main()
...{
char buf[32];
ToHex(buf,334565);
cout<<buf<<endl;
system("pause");
return 0;
}
9643

被折叠的 条评论
为什么被折叠?



