Hi
I fetch Bluetooth data Convert to int
os mac / python 3.7.3
int.from_bytes(b'\x8c\x7b\xd3\x3c', byteorder='big', signed=True)
-1938042052
os MicroPython v1.11-624-g210d05328 / python 3, 4, 0
int.from_bytes(b'\x8c\x7b\xd3\x3c', 'big', True)
2356925244
MicroPython ouput value
Not what I want
How to get -1938042052
thank
function int.from_bytes Different results
Re: function int.from_bytes Different results
MicroPython doesn't currently support the "signed" parameter to from_bytes.
In the code for from_bytes it says:
So it matches the CPython behavior if you set signed=False (which probably isn't what you want).
However, the workaround is to use struct.unpack instead
(Note that unpack returns a single-element tuple here).
In the code for from_bytes it says:
Code: Select all
// TODO: Support signed param (assumes signed=False at the moment)
(void)n_args;
However, the workaround is to use struct.unpack instead
Code: Select all
>>> struct.unpack('>i', b'\x8c\x7b\xd3\x3c')
(-1938042052,)