Convert 10 To Bytes, Strange Result
i = 11 print(i.to_bytes(1,'big')) b'\x0b' i = 10 print(i.to_bytes(1,'big')) b'\n' It should be b'\x0a' Why i got b'\n'?
Solution 1:
Well, as khelwood also explained in his comment, at roughly the same time, here's the deal:
As the newline
character has a "c-style shorthand", namely \n
, and also a numerical value of 0x0a, or 10 in decimal, these representations are equivalent. It's only that Python decides to show you the traditional escape sequence.
To be fair, character 11, or 0x0b is the vertical tab, so it could be represented as \v
, but apparently Python does not do that one.
Please see https://en.wikipedia.org/wiki/Control_character#In_ASCII and http://www.asciitable.com/ for details.
Post a Comment for "Convert 10 To Bytes, Strange Result"