Archived

This topic is now archived and is closed to further replies.

Austrian Coder

Conver e.g. 0x16004360 into something readable

Recommended Posts

Not really. I need a Hex2Ascii konverter. I am working on a linux driver and i want know to readout all hardware registers. For instance, a return value of an register can be: 0x01d5

Now i want to check, if such a value contains an usefull info like an number or an letter.

PS: Found one: http://www.programmersheaven.com/zone3/cat415/30033.htm

Now the next problem: a hex counter. It is very hard for me to do such things, because i nerver worked if hex's.

[edited by - Austrian Coder on April 20, 2004 6:44:59 PM]

Share this post


Link to post
Share on other sites
char hexDigits[16] = {''0'', ''1'', ''2'', ''3'', ''4'', ''5'', ''6'', ''7'', ''8'', ''9'', ''A'', ''B'', ''C'', ''D'', ''E'', ''F''};

void HexToAscii(unsigned char c)
{
cout << "0x" << hexDigits[c >> 4]
<< hexDigits[c & 0x0F];
}

void HexToAscii(unsigned short s)
{
cout << "0x" << hexDigits[s >> 12]
<< hexDigits[(s >> 8) & 0x0F]
<< hexDigits[(s >> 4) & 0x0F]
<< hexDigits[s & 0x0F]
}

void HexToAscii(unsigned int i)
{
cout << "0x" << hexDigits[i >> 28]
<< hexDigits[(i >> 24) & 0x0F]
<< hexDigits[(i >> 20) & 0x0F]
<< hexDigits[(i >> 16) & 0x0F]
<< hexDigits[(i >> 12) & 0x0F]
<< hexDigits[(i >> 8) & 0x0F]
<< hexDigits[(i >> 4) & 0x0F]
<< hexDigits[i & 0x0F]
}

Share this post


Link to post
Share on other sites