Over a million developers have joined DZone.

C C++ Convert Hex To Ascii

DZone's Guide to

C C++ Convert Hex To Ascii

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

// Presented with hex such as 0x12345abc perhaps there is a spot in there
// which represents an ascii char - such as 53 would be 'S'
// Common when dealing with hardware-related data structures and wire
// protocols


*To convert 53 to the character 'S':
*char returnVal = hexToString('5', '3');
char hexToAscii(char first, char second)
char hex[5], *stop;
hex[0] = '0';
hex[1] = 'x';
hex[2] = first;
hex[3] = second;
hex[4] = 0;
return strtol(hex, &stop, 16);
int main(int argc, char* argv[])
printf("%c\n", hexToAscii('5', '3'));

produces this output:

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

c ,c++

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}