Reputation: 3
My code looks like this :
import struct
str = "AAAAAAA"
len = len(str)+32
package = struct.pack("!H",len)
print repr(package)
the result is :
"\x00'"
When I use len = len(str)
the result is \x00\x07
Why when len
is larger than 32,it is not working?
Upvotes: 1
Views: 47
Reputation: 123483
You're misunderstanding the "\x00'"
result. It's a mixture of a string hexadecimal character code value and a regular printable ASCII character. If it were displayed purely in hexadecimal character codes, it would be "\x00x\x27"
.
The \x27
in decimal is the integer 39
, which is the result of len(str)+32
. It's also the character code of the '
(single quote) character, which is part of what repr()
is displaying.
Upvotes: 1