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
HexToDecimal
-
Matrixv8
- Posts: 23
- http://meble-kuchenne.info.pl
- Joined: Mon Jun 03, 2024 2:51 am
- Been thanked: 4 times
-
chipfryer27
- Valued Contributor
- Posts: 1954
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 425 times
- Been thanked: 647 times
Re: HexToDecimal
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
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
-
Steve-Matrix
- Matrix Staff
- Posts: 1797
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 258 times
- Been thanked: 415 times
Re: HexToDecimal
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
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