首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

求将下面C++的CRC校验代码转换成java格式的

2013-06-25 
求将下边C++的CRC校验代码转换成java格式的?void y_crc(unsigned char *buff, unsigned short bufflen, un

求将下边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

热点排行