[Python] How do I convert a byte to an integer in python when it has the byte markers...

Discussão em 'Python' iniciado por Stack, Junho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have a function in python which reads the first 3 bytes in a serial port buffer. I then want to convert the third byte to an integer which will allow me to determine the length of the total byte array. However, when I use int() I get the following error:

    ValueError: invalid literal for int() with base 16: b'\x16'

    I've tried slicing the string further along, but that just returns b''. How can I convert the byte to an integer?

    Thank you!

    Continue reading...

Compartilhe esta Página