我在
android /
java中写了一个校验和计算函数.功能如下
void CalculateCheckSum( byte[] bytes ){ short CheckSum = 0,i = 0; for( i = 0; i < bytes.length; i++ ){ CheckSum = (short) ((short)CheckSum + (short)bytes[i]); } Log.i("Checksum",Integer.toHexString(CheckSum)); }
计算校验和的输入值为0xEF,0x01,0xEF,0x33,0x0C,0xB8,0xE5,0xFC,0x34,0xFF,0xFF.我手动计算校验和值,结果为0xCE4.当使用上面的函数时,我的答案为0xFFFFFFE4.在我的计算中是否有任何错误,如果是,那么请纠正我.
谢谢