fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <stdio.h>
  10. #include <stdint.h>
  11. #include <string.h>
  12.  
  13. int main()
  14. {
  15. uint32_t i;
  16. uint32_t bitbang, j;
  17. uint32_t crc_calc;
  18.  
  19. uint8_t data_in[] = {0x43, 0x00, 0xE2, 0x39, 0x30, 0x00, 0x00, 0x2D, 0x58, 0x18, 0xED, 0x1B, 0x11, 0x00, 0x05, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x2D, 0x00, 0x00, 0x00, 0xE9, 0x01, 0x00, 0x01, 0x4E, 0x6E};
  20.  
  21. crc_calc = 0xC181; //Se for comunicação modbus via rádio Lora Radioenge
  22. //crc_calc = 0xFFFF; //Se for comunicação modbus via RS485
  23.  
  24. for(i=0; i<31; i++) {
  25. crc_calc ^= (((uint16_t)data_in[i]) & 0x00FF);
  26.  
  27. for(j=0; j<8; j++) {
  28. bitbang = crc_calc;
  29. crc_calc >>= 1;
  30.  
  31. if(bitbang & 1) {
  32. crc_calc ^= 0xA001;
  33. }
  34. }
  35. }
  36.  
  37. //return (crc_calc&0xFFFF);
  38.  
  39. printf("\n\nCRC: %u", crc_calc);
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 5284KB
stdin
45
stdout

CRC: 0