I am trying to translate a CRC8 function from C to Java.
I got this code from the hardware manufacturer:
uint8_t CRCCalc (uint8_t* pointer, uint16_t len) {
    uint8_t CRC = 0x00;
    uint16_t tmp;
    while(len > 0) {
        tmp = CRC << 1;
        tmp += *pointer;
        CRC = (tmp & 0xFF) + (tmp >> 8);
        pointer++;
        --len;
    }
    return CRC;
}
My Java code is:
private int getCheckSum(byte[] data) {
        int tmp;
        int res = 0;
        for(int i = 0; i < data.length; i++) {
            tmp = res << 1;
            tmp += 0xff & data[i];
            res = (tmp & 0xff) + (tmp >> 8);
        }
        return res;
    }
Usually all works fine, but sometimes for example: For the hex 0997AD0200, the CRC should be 4, but my code gives me 8
I'm not sure what I missed.
 
     
    