日期:2014-05-20  浏览次数:20624 次

求将下边C++的CRC校验代码转换成java格式的?
void y_crc(unsigned char *buff, unsigned short bufflen, unsigned char *lsb, unsigned char *msb)
{
??? ? ? unsigned short crc = 0xFFFF;? ?? ?? ? // Preload to FFFF
??? ? ? unsigned short tempresults;? ?? ?? ???// Just a temporary results holder
??? ? ? unsigned short bitindex;? ?? ?? ???// 0 - 7
??? ? ? unsigned short byteindex;? ?? ?? ???// The byte pointer into the byte array that holds
??? ? ? // the command to be checked.
??? ? ? unsigned char??placeholder;? ?? ?? ???// A place to put the byte while we work on it.
?
??? ? ? for (byteindex = 0; byteindex < bufflen ; byteindex++) // begin checking after SOH and before CRC bytes
??? ? ? {
??? ? ? ? ? ? ? placeholder = *(buff + byteindex);
??? ? ? ? ? ? ? for(bitindex = 0; bitindex <= 7; bitindex++)
??? ? ? ? ? ? ? {
??? ? ? ? ? ? ? ? ? ? ? tempresults = (crc >> 15) ^ (placeholder >> 7);? ? // Shift CRC right 15 bits then do a bitwise XOR
??? ? ? ? ? ? ? ? ? ? ? crc <<= 1;? ?? ?? ?? ? // Shift CRC left one bit and store it in CRC
??? ? ? ? ? ? ? ? ? ? ? if(tempresults)
??? ? ? ? ? ? ? ? ? ? ? {
??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? crc ^= 0x1021;? ?? ?? ???// Standard CCITT Polynomial X16+X12+X5+1
??? ? ? ? ? ? ? ? ? ? ? }
??? ? ? ? ? ? ? ? ? ? ? placeholder <<= 1;
??? ? ? ? ? ? ? }
??? ? ? }
??? ? ? *lsb = crc&0x00ff;? ? ? ? 
??? ? ? *msb = (crc>>8)&0x00ff;? ? ? ? 
}
CRC校验 CRC16算法 CRC16算法转为java java?CRC java?CRC16算法

------解决方案--------------------
java.util.zip.CRC32