when i change number into hex in struct module of python,
>>> import struct
>>> struct.pack("i",89)
'Y\x00\x00\x00'
>>> struct.pack("i",890)
'z\x03\x00\x00'
>>> struct.pack("i",1890)
'b\x07\x00\x00'
what is the meaning of “Y,z,b” in the output?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re not converting to hex. You’re packing the integer as binary data… in this case, little-endian binary data. The first characters are just the corresponding ASCII characters to the raw bytes; e.g.
89isY,122isz, and98isb.packproduces'\x59\x00\x00\x00'for0x00000059;'\x59'is'Y'.'\x7a\x03\x00\x00'for0x0000037a;'\x7a'is'z'.'\x62\x07\x00\x00'for0x00000762;'\x62'is'b'.See the below ASCII table.
(source: asciitable.com)