I am currently working on a project, having an embedded system sending data to a PC via radio. The packets get a crc16 checksum at the end and it's calculated based on this algorithm:
uint16_t crc16 (const uint8_t * buffer, uint32_t size) {
    uint16_t crc = 0xFFFF;
    if (buffer && size)
        while (size--)
        {
            crc = (crc >> 8) | (crc << 8);
            crc ^= *buffer++;
            crc ^= ((unsigned char) crc) >> 4;
            crc ^= crc << 12;
            crc ^= (crc & 0xFF) << 5;
        }
    return crc;
}
Now I am looking for an equivalent in Java. I already found a good one here: http://introcs.cs.princeton.edu/java/51data/CRC16CCITT.java.html
public class CRC16CCITT { 
    public static void main(String[] args) { 
        int crc = 0xFFFF;          // initial value
        int polynomial = 0x1021;   // 0001 0000 0010 0001  (0, 5, 12) 
        // byte[] testBytes = "123456789".getBytes("ASCII");
        byte[] bytes = args[0].getBytes();
        for (byte b : bytes) {
            for (int i = 0; i < 8; i++) {
                boolean bit = ((b   >> (7-i) & 1) == 1);
                boolean c15 = ((crc >> 15    & 1) == 1);
                crc <<= 1;
                if (c15 ^ bit) crc ^= polynomial;
             }
        }
        crc &= 0xffff;
        System.out.println("CRC16-CCITT = " + Integer.toHexString(crc));
    }
}
But this doesnt work with my C Code.
Is anybody able to deliver an adaption or solution for a C and Java equivalent algorithm? Thank you!
 
     
    