Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1234

Python • Convert Integer to Hex Byte for use in I2C comms

$
0
0
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?

Statistics: Posted by PhilPryer — Mon Apr 29, 2024 4:19 pm



Viewing all articles
Browse latest Browse all 1234

Trending Articles