fork download
  1. #include <stdio.h>
  2. char CRC8_SAE_J1850_ZERO(char data[], int len);
  3. int main(void) {
  4. char data [] ={0xF2,0x00,0x01,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  5. int len = 32,crc;
  6. crc = CRC8_SAE_J1850_ZERO (data, len);
  7. printf("crc %x",crc);
  8. return 0;
  9. }
  10.  
  11. char CRC8_SAE_J1850_ZERO(char data[], int len)
  12. {
  13. char crc = 0x00;
  14. int i, j;
  15.  
  16. for (i = 0; i < len; i++) {
  17. crc ^= data[i];
  18. for (j = 0; j < 8; j++) {
  19. if (crc & 0x80) {
  20. crc = (crc << 1) ^ 0x1D;
  21. } else {
  22. crc <<= 1;
  23. }
  24. }
  25. }
  26. return crc;
  27. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
crc 3c