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

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -