could someone explain to me why some of the integers passed to to_bytes() method gives a strange result?
>>> b = 5152
>>> b.to_bytes(2, byteorder='big')
b'\x14 '
>>> b = 5153
>>> b.to_bytes(2, byteorder='big')
b'\x14!'
>>> b=16592
>>> b.to_bytes(2, byteorder='big')
b'@\xd0'
How to interpret '@' '!' ' '? For 16592 I expected b'\x40\xd0'.
I read Python 3 documentation and all examples from there work fine. Python 3 to_byte() description.
>>> b=1024
>>> b.to_bytes(2, byteorder='big')
b'\x04\x00'
I also try an example for this Stackoverflow post and it works like a charm.
>>> b = 1245427
>>> b.to_bytes(3, byteorder='big')
b'\x13\x00\xf3'
Aditional info:
Python 3.6.4 (default, Feb 1 2018, 11:06:09)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Program runs on Fedora 27.