Hello Guys, I am doing a project. I am reading the output from the ADC,Hex value which i want to convert into ASCII value because i have written the code for display driver to accept ascii values. can any one let me the know C Routine for Hex to ASCII. Mike
Why can't you just use sprintf() ?
This one I use... void send_hex_byte(unsigned char d) { unsigned char t; t=d>>4; t+='0'; if (t>=(10+'0')) { t+=('A'-10-'0'); } uart_tx(t); // call to your function here t=d&0x0F; t+='0'; if (t>=(10+'0')) { t+=('A'-10-'0'); } uart_tx(t); // call to your function here }
simple lookup array works --- code char digit [16] = {'0','1','2','3','4','5','6','7', '8','9','A','B','C','D','E','F'}; ascii value is - digit [hex_value]
Also: strtol() / strtoul()