I have this uart sequence.
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes);
std::string str(bytes.begin(), bytes.end());
id(volume2).publish_state( ?? str.substr(5,2) ?? );
The string I get from the uart is like XXXXX2F.
It is the hex value 2F I need to change into decimal value 47, but with the twist that 2F is actually a string.
I do not care if 2F is made into a hex value first and then converted or if 2 and F is converted as 2 hex values to dec. I can always multiple the first value of the 2 with 16 and add the other to the result afterwards.
When that part is solved, then I also need to get the other way to later write a decimal value to uart as a hex value in a string.
And the same here I can make an int division with 16 to get the first value in a 2 part hex value and then the modulus to get the second part, if converting hex values is easier that way.
How do I do that conversion?