Page 1 of 1

HexToDecimal

Posted: Thu Mar 12, 2026 2:10 am
by Matrixv8
Hi everyone, I search the forum and could not find a way to convert HexToDecimal, function or otherwise that I could use while reading UART data. IE: receiving bytes and convert so I can read Hex data and convert it to a usable form. Does someone have a solution?

Thank you for your help.

Regards,
Pierre

Re: HexToDecimal

Posted: Thu Mar 12, 2026 3:33 am
by chipfryer27
Hi

Not sure I know what you want to do as you don't say what a usable form actually is.

You want to take a hex number arriving over your UART, then do what with it?

Regards

Re: HexToDecimal

Posted: Thu Mar 12, 2026 4:41 am
by mnfisher

Re: HexToDecimal

Posted: Thu Mar 12, 2026 8:34 am
by Steve-Matrix
As @chipfryer27 says, it depends on what you are actually receiving. If you are receiving string data in a human-readable form that is represented as a hexadecimal string, then you can convert it using the example in @mnfisher's post.

But often you may be receiving bytes that are actually numbers (rather than a string representation of a number). In this case, it's just a number. For example, the number might be 255 (in decimal) or 0xFF (in hexadecimal), but behind the scenes it is still the same number and requires no actual conversion. Conversion is only necessary when you are transferring string data. There is a discussion about this here:
https://www.flowcode.co.uk/forums/viewtopic.php?p=14518