Python¿ÉÄÜÓõõ½µÄ3ÖÖ16½øÖÆÐÎʽ
1¡¢ '0xabc¡¯ÐÎʽµÄ16½øÖÆ
ÊäÈë
a = '0x53'
print(type(a))
print(len(a))
b = int(a,16)
print(b)
print(type(b))
Êä³ö
<class 'str'>
4
83
<class 'int'>
ÔÚpythonÖÐ,ÒÔ×Ö·û´®ÐÎʽд³ö16½øÖƵĸñʽ¼´Îª¡¯0xabc¡¯ ת»»Îª10½øÖÆΪc+b* 16+a* 16^2
2¡¢¡¯\xhh¡¯ÐÎʽµÄ16½øÖÆ
ÊäÈë
a = '\x53'
print(type(a))
print(len(a))
print(a)
Êä³ö
<class 'str'>
1
S
¶øÕâÀïµÄ´òÓ¡³öÀ´µÄS,ÕýÊÇÊ®½øÖÆ83,Ò²¾ÍÊÇ16½øÖÆ53,¶ÔÓ¦µÄASCIIÂëÖµ¡£
µ±³¬³öasciiÂ뷶ΧʱÊäÈë
print('\x80') print('\x88') print('\x98')
Êä³öΪ€ ? ?
3¡¢b¡¯hh¡¯ ÐÎʽµÄ16½øÖÆ(ͨ¹ýbǰ׺½«×Ö·û´®×ª»»³É bytes)
ÊäÈë
a = b'53'
print(type(a))
print(len(a))
print(a)
b = str(a)
print(type(b))
print(len(b))
print(b)
c = bytes(chr(int('0x%s'%str(b)[2:-1],16)),encoding="ascii")
print(type(c))
print(len(c))
print(c)
d = int('0x%s' % str(b)[2:-1], 16)
print(d)
e = chr(d)
print(e)
f = bytes(e,encoding="ascii")
print(f)
Êä³ö
<class 'bytes'>
2
b'53'
<class 'str'>
5
b'53'
<class 'bytes'>
1
b'S'
83
S
b'S'
×¢ÒâasciiÂëΪ0-127,ת×Ö½ÚµÄʱºòÐèҪעÒâ²»Òª³¬³ö·¶Î§,·ñÔò»á±¨´í¡£ ³¬³ö·¶Î§Çë²Î¿¼±ðµÄÎÄÕÂ: https://blog.csdn.net/soy_sauces/article/details/100836412
|