fork download
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <stdint.h>
  4.  
  5. uint32_t crc32(const char *s,size_t n) {
  6. uint32_t crc=0xFFFFFFFF;
  7.  
  8. for(size_t i=0;i<n;i++) {
  9. char ch=s[i];
  10. for(size_t j=0;j<8;j++) {
  11. uint32_t b=(ch^crc)&1;
  12. crc>>=1;
  13. if(b) crc=crc^0x04C11DB7;
  14. ch>>=1;
  15. }
  16. }
  17.  
  18. return ~crc;
  19. }
  20.  
  21. int main()
  22. {
  23. char* a = "Hello World";
  24. int crc = crc32(a, 11);
  25. printf("Hello World %X", crc);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 5516KB
stdin
123
stdout
Hello World FC6BF04E