Posted on 2009-09-15 22:40
S.l.e!ep.¢% 阅读(644)
评论(0) 编辑 收藏 引用 所属分类:
Algorithm
#include <iostream>
void Int2Hex(int nNum, char* pszBuf)
{
char szBuf[255] = {0};
int i = 0;
while( nNum != 0 )
{
int j = nNum & 0xF;
if( j >= 10 )
{
szBuf[i] = (char)('A'+(j-10));
}
else
{
szBuf[i] = (char)('0'+(j));
}
i++;
nNum = nNum >> 4;
}
int k = 2;
pszBuf[0] = '0';
pszBuf[1] = 'x';
while(i > 0)
{
i--;
pszBuf[k] = szBuf[i];
k++;
}
}
int main()
{
for(int i = 0; i <= 1000; i++)
{
char szBuf[255] = {0};
Int2Hex(i, szBuf);
//atoi(szBuf)
if( i != atoi(szBuf) )
std::cout << "Error" << std::endl;
}
}