fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. int main(void) {
  4. // your code goes here
  5. uint8_t crc = 0xFF;
  6. uint8_t crc_new = 0;
  7. uint32_t input_data = 0xD07A65;
  8. // uint32_t input_data = 0xA0CA85;
  9. //uint32_t input_data = 0x3B007C;
  10. for (int i = 23; i >= 0; i--)
  11. {
  12. //CRC[7] in bit 0
  13. uint32_t crc_xor = (crc & 0x80) >> 7;
  14. // if (crc_xor)
  15. // {
  16. // crc_xor = 0x
  17. // }
  18. //CRC_NEW = CRC << 1
  19. crc_new = crc << 1;
  20. //crc_new_bit_4 = crc_new[4] ^ crc[7]
  21. uint8_t crc_new_bit_4 = (crc_new & 0x10) ^ (crc_xor << 4);
  22. uint8_t crc_new_bit_3 = (crc_new & 0x8) ^ (crc_xor << 3);
  23. uint8_t crc_new_bit_2 = (crc_new & 0x4) ^ (crc_xor << 2);
  24. uint32_t crc_new_bit_0 = (input_data & (1 << i)) ^ (crc_xor << i);
  25. if (crc_new_bit_4 & 0x10)
  26. {
  27. crc_new |= 0x10;
  28. }
  29. else
  30. {
  31. crc_new &= ~0x10;
  32. }
  33. if (crc_new_bit_3 & 0x8)
  34. {
  35. crc_new |= 0x8;
  36. }
  37. else
  38. {
  39. crc_new &= ~0x8;
  40. }
  41. if (crc_new_bit_2 & 0x4)
  42. {
  43. crc_new |= 0x4;
  44. }
  45. else
  46. {
  47. crc_new &= ~0x4;
  48. }
  49. if (crc_new_bit_0 & (1 << i))
  50. {
  51. crc_new |= 0x1;
  52. }
  53. else
  54. {
  55. crc_new &= ~0x1;
  56. }
  57. crc = crc_new;
  58.  
  59. }
  60. crc ^= 0xFF;
  61. printf("crc=%X", crc);
  62. return 0;
  63. }
  64.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
crc=88