I need to convert a decimal integer in range 0 to 255 into a byte with constant length.
The byte will be appended to a bytearray to provide the variable data input to the I2C component's register.
Currently I have used hex(integer) but this produces a variable length string.
For Integer decimal 1 I need the output to be b'\x01' rather than b'\x1'
How do I achieve this?
The byte will be appended to a bytearray to provide the variable data input to the I2C component's register.
Currently I have used hex(integer) but this produces a variable length string.
For Integer decimal 1 I need the output to be b'\x01' rather than b'\x1'
How do I achieve this?
Statistics: Posted by PhilPryer — Mon Apr 29, 2024 4:19 pm