# Hex to ASCII for display

#### 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"?

#### mukesh1

Joined Mar 22, 2020
45
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"?
I want to show " 41" on LCD display

#### Dave Lowther

Joined Sep 8, 2016
57
I want to show " 41" on LCD display
For each nibble:
if nibble < 10 then output char or byte value of '0' + nibble
else output char or byte value of 'A' + nibble - 10

#### 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:

#### Dave Lowther

Joined Sep 8, 2016
57
You have 2 numbers...
I think the OP just has one number contained in a byte
So where you said "msb = (number & 0xF0) >> 8;" I think the 8 should be a 4
Edit - ignore this as the post I was talking about has been edited to correct it

Last edited:

#### MrSalts

Joined Apr 2, 2020
279
What kind of LCD do you have? A 1602 (2x16 character display) or a pixelated graphic display (126x64 or other)?

#### click_here

Joined Sep 22, 2020
177
I think the OP just has one number contained in a byte
So where you said "msb = (number & 0xF0) >> 8;" I think the 8 should be a 4
Fast fingers - I quickly edited it, but you managed to catch me!

#### Dave Lowther

Joined Sep 8, 2016
57
Fast fingers - I quickly edited it, but you managed to catch me!
Sorry. I've edited my post now to say it should be ignored as you corrected your post.

#### 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';