Hex to ASCII conversion

Hello All,

My CH4 sensor giving me HEX string for different functions. i want to convert it so other people can easily read it.
For example: 50514643F322020 (Serial Number) for one function
and 01C8 (Concentration of CH4 in ppm) for second function.
Also, the value concentration of CH4 change for different gas solution.
can somebody help me in this regards??

Thanks in advanced.

it's conventional for some sensor to report values as binary, typically grouped as one or more 8-bit bytes.

binary values can be "displayed" in many ways: graphically, binary bits, octal, hexadecimal, decimal digits, ...

what format would you like to display the value to "easily read it"?

have you simply tried Serial.println (value)

Thank you for your response.
Actually, my CH4 sensor using Modbus, therefore it is printing data in data Telegram in HEX string.

I want to print it in ASCII character, which is easily readable .

This part is unclear: what do you have in mind? Please fill up the example below:

I'm getting                 I want do display
50514643F322020             ........
01C8                        ........

aren't HEX strings, like all strings, in ASCII?

do you want the translate the HEX strings to Decimal strings?
for example 0x1234 to 4660?

So when i send a query to my slave (CH4 sensor), it sending data into ```
505146434F322020 which mean is "PQFCO2" my sensor serial name and 01C8 means 456 ppm.

i have no idea how to decode/translate the value or string 505146434F322020 into serial # and ppm value you indicate

looks like you've received the value from your sensor in a readable form

Its in Hexadecimal string and i want to display is into ASCII character.

if it's a hex string it's already ascii

a binary value of 1010 has a value of 10 and is displayed as an ascii 'A' or 'a'

not clear what you're asking. do you mean you want to display it's binary value as a hexadecimal string?

for your reference, i attached a pic, what i want to do.

I think I get it, even if the OP hasn't filled up my table form post #4 (@ashish_senger Why, by the way?).

ox01c8 is indeed decimal 456 from post #6 and 505146434F322020, once interpreted as hex and broken into bytes, encodes the string "PQFCO2 " (with 2 trailing spaces).

What is unclear, is whether the OP is receiving ASCII strings, but I think that it's the case.

This is a well known standard, no need to explain it to anybody. Better fill that table...

I'm getting I want do display
50514643F322020 PQFCO2
01C8 456 ppm

We are making progress. Two more questions: are you receiving that data as strings? If that's the case: are these strings fixed in size?

yes, it is complete as a string.

code below produces

PQFC⸮"

char s [] = {  0x50, 0x51, 0x46, 0x43, 0xF3, 0x22, 0x020, 0x0 };

void
setup (void)
{
    Serial.begin (9600);
    Serial.println (s);
}

// -----------------------------------------------------------------------------
void
loop (void)
{
}

Thank you for your help.
I will work with this code.

So that solved it for you? I'm even more confused.

this, "50514643F322020" is the received data where each byte is displayed in hex w/o spaces in between