1

I'm trying use the to_bytes function. In most cases it works good for me but not always. For example:

byteData = (212168254).to_bytes(4,'big')
print (byteData)

print should give me b'\x0c\xa5\x6e\x3e' but it gives me b'\x0c\xa5n>'. Why is that?

smottt
  • 3,272
  • 11
  • 37
  • 44
  • 3
    No - that's correct. `6e` and `3e` are printable characters that can be displayed as "n" and ">" - so Python displays them as such. – Jon Clements Aug 29 '17 at 06:36
  • If you want hex escapes for everything, do your own hex encoding. – user2357112 Aug 29 '17 at 06:37
  • but still it doesn't looks like lenght of bytes is 4 :) –  Aug 29 '17 at 06:41
  • @Fuk one thing is the lenght and another completly is the representation, python only "shows" them as `n` and `>` for the print function – Netwave Aug 29 '17 at 07:22
  • Possible duplicate of [Python 2,3 Convert Integer to "bytes" Cleanly](https://stackoverflow.com/questions/14043886/python-2-3-convert-integer-to-bytes-cleanly) – stovfl Aug 29 '17 at 15:16

0 Answers0