python - struct.pack() failing with int > 127 -
python - struct.pack() failing with int > 127 -
why
struct.pack("!bbbb", 0x2, r, g, b) failing in python code when r, g, or b > 127?
i know "b" means size of given value 1 byte according struct docs, why fail values on 127?
according the documentation, b stands for:
signed char
which means valid range [-128, 127]. , that's error messages says explicitly:
>>> struct.pack("!bbbb", 0x2, 127, 127, 128) traceback (most recent phone call last): file "<stdin>", line 1, in <module> struct.error: byte format requires -128 <= number <= 127 using b yields no error:
>>> struct.pack("!bbbb", 0x2, 127, 127, 128) '\x02\x7f\x7f\x80' python sockets struct.pack
Comments
Post a Comment