Page 1 of 1

How do I convert a hex substring to int

Posted: Wed Aug 11, 2021 10:23 pm
by dougconran
I have a hex string:

Code: Select all

mystr  = b'FFF7E7FF704268426803FF380E53131212121312000012BB01BA3300008200016D9E00016C790000865D00008206003723630D016E0271027103E8'
and want to get the int value of mystr[44:46] - it should come to 18

In python I would do

Code: Select all

int(mystr[44:46],base=16)
but that doesn't work in MP. I've googled around but can only find python examples.

Re: How do I convert a hex substring to int

Posted: Thu Aug 12, 2021 5:09 am
by JennaSys
When I try

Code: Select all

int(mystr[44:46],16)
in MP v1.16 on an ESP8266 it gives me a result of 18

Re: How do I convert a hex substring to int

Posted: Thu Aug 12, 2021 9:12 am
by dougconran
:oops: Yes, that has worked for me as well. How simple and obvious these things are when you know! - Thanks

Re: How do I convert a hex substring to int

Posted: Thu Aug 12, 2021 10:17 pm
by robertcarell
dougconran wrote:
Thu Aug 12, 2021 9:12 am
:oops: Yes, that has worked for me as well. How simple and obvious these things are when you know! - Thanks
well said and that's why forums are for !!!