@@ -0,0 +1,1188 @@
+package com.neucrack.tool;%0D%0A%0D%0Apublic class CRC %7B%0D%0A%0D%0A%09static public int CRC16Calculate(byte data%5B%5D, int size)%0D%0A%09%7B%0D%0A%09    short out = 0;%0D%0A%09    int bits_read = 0, bit_flag;%0D%0A%0D%0A%09    /* Sanity check: */%0D%0A%09    if(data == null)%0D%0A%09        return 0;%0D%0A%0D%0A%09    int count=0;%0D%0A%09    while(size %3E 0)%0D%0A%09    %7B%0D%0A%09        bit_flag = out %3E%3E 15;%0D%0A%0D%0A%09        /* Get next bit: */%0D%0A%09        out %3C%3C= 1;%0D%0A%09        out %7C= (data%5Bcount%5D %3E%3E bits_read) & 1; // item a) work from the least significant bits%0D%0A%0D%0A%09        /* Increment bit counter: */%0D%0A%09        bits_read++;%0D%0A%09        if(bits_read %3E 7)%0D%0A%09        %7B%0D%0A%09            bits_read = 0;%0D%0A%09            ++count;%0D%0A%09            size--;%0D%0A%09        %7D%0D%0A%0D%0A%09        /* Cycle check: */%0D%0A%09        if(bit_flag!=0)%0D%0A%09            out %5E= 0x8005;%0D%0A%0D%0A%09    %7D%0D%0A%0D%0A%09    // item b) %22push out%22 the last 16 bits%0D%0A%09    int i=0;%0D%0A%09    for (i = 0; i %3C 16; ++i) %7B%0D%0A%09        bit_flag = out %3E%3E 15;%0D%0A%09        out %3C%3C= 1;%0D%0A%09        if(bit_flag!=0)%0D%0A%09            out %5E= 0x8005;%0D%0A%09    %7D%0D%0A%0D%0A%09    // item c) reverse the bits%0D%0A%09    int crc = 0;%0D%0A%09    i = 0x8000;%0D%0A%09    int j = 0x0001;%0D%0A%09    for (; i != 0; i %3E%3E=1, j %3C%3C= 1) %7B%0D%0A%09        if (0!=(i & out)) crc %7C= j;%0D%0A%09    %7D%0D%0A%0D%0A%09    return crc&0xffff;%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A

add crc16