{
unsigned char * dataPtr = (unsigned char *) Buff_addr;
unsigned short index = 0;
unsigned short crc = 0;
while (len -)
{
crc = (unsigned char) (crc >> 8) | (crc << 8);
crc ^ = dataPtr [index + +];
crc ^ = (unsigned char) (crc & 0xff) >> 4;
crc ^ = (crc << 8) << 4;
crc ^ = ((crc & 0xff) << 4) << 1;
}
return crc;
}
best you can have a simple test can be run in eclipse below ~
------ Solution ---------------------- ----------------------
try this with c and java ran out the same results
java in short max 32767 , only with int it.
public class Test01 {
public static void main(String[] args) {
int crc = CRC16(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x03, 0x02 }, 6);
System.out.println(Integer.toHexString(crc));
}
static int CRC16(byte[] buffer, int len) {
int index = 0;
int crc = 0;
while (len-- > 0) {
crc = (crc >> 8) | (crc << 8);
crc ^= buffer[index++];
crc ^= (crc & 0xff) >> 4;
crc ^= (crc << 8) << 4;
crc ^= ((crc & 0xff) << 4) << 1;
crc &= 0xFFFF;
}
return crc;
}
}
------ For reference only ----------------------------------- ----
should be sent to the C / C + + blocks it. . . . . .
------ For reference only -------------------------------------- -
java plate right, see the meaning of the questions c ~ is an algorithm into java version of ~
------ For reference only -------- -------------------------------
top sink so fast ~ ~
------ For reference only ---------------------------------------
this function is to complete what function ? Charset transcoding ?
------ For reference only -------------------------------------- -
Guo Jia is very fierce .
------ For reference only -------------------------------------- -
Guo Jia is very fierce . seeking points
------ For reference only ---------------------------------------
knot stickers ! Thank handy !
没有评论:
发表评论