def decode(value): B1 = (value >> 8) & 0xFF B2 = value & 0xFF o1 = (B1 >> 2) & 0x3F o2 = B1 & 3 o3 = (B2 >> 4) & 0x0F o4 = B2 & 0x0F return o1, o2, o3, o4 def encode(b1, b2, b3, b4): B1 = ((b1 << 2) & 0xFC) | (b2 & 3) B2 = ((b3 << 4) & 0xF0) | (b4 & 0x0F) return ((B1 << 8) & 0xFF00) | B2 if __name__ == '__main__': print decode(0x995f) print hex(encode(38, 1, 5, 15))
发表评论