# -*- coding: utf-8 -*- import struct import math deflong_to_bytes(n): s = b'' pack = struct.pack while n > 0: s = pack('>I', n & 0xffffffff) + s n = n >> 32 for i inrange(len(s)): if s[i] != b'\000'[0]: break else: s = b'\000' i = 0 s = s[i:] return s
#字节逆序 defbyteinvert(str_bin): ret='' for i inrange(len(str_bin)//8): ret+=str_bin[i*8:i*8+8][::-1] return ret
#标准曼彻斯特 defMCST_stand(str_bin): ret='' for i inrange(len(str_bin)//2): x=str_bin[i*2:i*2+2] if x=='01': ret+='0' elif x=='10': ret+='1' else: return'stand manchester decode wrong!' return ret
#IEEE规范的曼彻斯特 defMCST_IEEE(str_bin): ret='' for i inrange(math.ceil(len(str_bin)/8)): x=str_bin[i*2:i*2+2] if x=='01': ret+='1' elif x=='10': ret+='0' else: return'stand manchester decode wrong!' return ret
#差分曼彻斯特 defMCST_diff(str_bin): ret='' for i inrange(0,len(str_bin)//2-1): x1=str_bin[i*2:i*2+2] x2=str_bin[i*2+2:i*2+4] if x1==x2: ret+='0' else: ret+='1' return ret