fork download
  1. def crc8_sae_j1850_zero(data):
  2. crc = 0x00
  3. polynomial = 0x1D
  4.  
  5. for byte in data:
  6. crc ^= byte
  7. for _ in range(8):
  8. if crc & 0x80:
  9. crc = (crc << 1) ^ polynomial
  10. else:
  11. crc <<= 1
  12. crc &= 0xFF # Ensure 8-bit CRC
  13.  
  14. return crc
  15.  
  16. # Example usage with your provided data:
  17. data = [0xF2, 0x00, 0x0D, 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, 0x00, 0x00, 0x00]
  18. calculated_crc = crc8_sae_j1850_zero(data)
  19. print(hex(calculated_crc)) # Output the calculated CRC in hexadecimal format
  20.  
  21.  
  22.  
Success #stdin #stdout 0.03s 63552KB
stdin
Standard input is empty
stdout
0x25