Hex to ASCII for display

Thread Starter

mukesh1

Joined Mar 22, 2020
45
Lets say we have HEX value,

(byte & 0xF0) // send upper nibble
((byte << 4) & 0xF0); // send lower nibble

How do I convert HEX to ASCII and display on LCD without sprintf itoa ?
 

Dave Lowther

Joined Sep 8, 2016
57
Lets say we have HEX value,

(byte & 0xF0) // send upper nibble
((byte << 4) & 0xF0); // send lower nibble

How do I convert HEX to ASCII and display on LCD without sprintf itoa ?
If your byte contains, for example, 0x41 which is the ASCII code for 'A' what do you want to show on the LCD "A" or "41"?
 

click_here

Joined Sep 22, 2020
177
You have 2 numbers...
Code:
lsb = number & 0x0F;
msb = (number & 0xF0) >> 4;
If the l/msb is below 10, add '0'
Code:
lsbAsASCII = lsb + '0';
If l/msb is 10 or over...
Code:
lsbAsASCII = (lsb - 0x0A) + 'A';
 
Last edited:

MrChips

Joined Oct 2, 2009
23,515
C:
lsb = (byte & 0x0F);
msb = (byte & 0xF0) >> 4;
lsb = (lsb < 10) ? lsb : lsb + 7;
msb = (msb < 10) ? msb : msb + 7;
lsb += '0';
msb += '0';
 
Top