def _calculate_checksum(value):
        """4.12 Checksum Calculation from an unsigned short input"""
        # CRC
        polynomial = 0x131  # //P(x)=x^8+x^5+x^4+1 = 100110001
        crc = 0xFF

        # calculates 8-Bit checksum with given polynomial
        for byteCtr in [ord(x) for x in struct.pack(">H", value)]:
            crc ^= byteCtr
            for bit in range(8, 0, -1):
                if crc & 0x80:
                    crc = (crc << 1) ^ polynomial
                else:
                    crc = (crc << 1)
        return crc
def _calculate_checksum ( value ) : polynomial = 0x131 crc = 0xFF for byteCtr in [ ord ( x ) for x in struct . pack ( ">H" , value ) ] : crc ^= byteCtr for bit in range ( 8 , 0 , - 1 ) : if crc & 0x80 : crc = ( crc << 1 ) ^ polynomial else : crc = ( crc << 1 ) return crc
4.12 Checksum Calculation from an unsigned short input