????????最近在搞阿里的物聯(lián)網(wǎng),其中使用到二進(jìn)制數(shù)據(jù)透?jìng)鞯常笈_(tái)使用python咸包,所以需要研究一下,二進(jìn)制數(shù)據(jù)的傳輸問題棒假。
Python版本:3.6
設(shè)備端發(fā)送二進(jìn)制數(shù)據(jù):
7F 00 41 41 16 03 1E 1F 03 02 1F 1E 02 9C 9C EA EA 16 57 58 59 5A 5B 5C 5D 5E 5F 60 61 57 58 59 5A 5B 5C 5D 5E 5F 60 61 50 51 52 53 54 55 56 57 58 59 5A 50 51 52 53 54 55 56 57 58 59 5A 7E 02 7E 01 3E 3F 7F
物聯(lián)網(wǎng)平臺(tái)接受數(shù)據(jù)并進(jìn)行base64編碼溯职,數(shù)據(jù):
fwBBQRYDHh8DAh8eApyc6uoWV1hZWltcXV5fYGFXWFlaW1xdXl9gYVBRUlNUVVZXWFlaUFFSU1RVVldYWVp+An4BPj9/
代碼:
import base64
src ="7F 00 41 41 16 03 1E 1F 03 02 1F 1E 02 9C 9C EA EA 16 57 58 59 5A 5B 5C 5D 5E 5F 60 61 57 58 59 5A 5B 5C 5D 5E 5F 60 61 50 51 52 53 54 55 56 57 58 59 5A 50 51 52 53 54 55 56 57 58 59 5A 7E 02 7E 01 3E 3F 7F"
src = src.replace(" ","")
res = base64.b64encode(bytearray.fromhex(src))
print(res)
print(res.decode())
temp ="fwBBQRYDHh8DAh8eApyc6uoWV1hZWltcXV5fYGFXWFlaW1xdXl9gYVBRUlNUVVZXWFlaUFFSU1RVVldYWVp+An4BPj9/"
vv = base64.b64decode(temp.encode())
print("++++++++++++++++++++++++++++++++++++++++++++")
print(vv)
print(len(vv))
for iin range(len(vv)):
print('{:08b}'.format(vv[i]))
print("++++++++++++++++++++++++++++++++++++++++++++")