fork(5) download
  1. int get_CRC( const void * pBuf, int len )
  2. {
  3. //TODO: implement crc
  4. unsigned int crc = 0;
  5. unsigned char i;
  6. unsigned char *ptr = (unsigned char *)pBuf;
  7. while( len-- ) {
  8. for(i = 0x80; i != 0; i = i >> 1) {
  9. if((crc & 0x8000) != 0) {
  10. crc = crc << 1;
  11. crc = crc ^ 0x1021;
  12. }
  13. else {
  14. crc = crc << 1;
  15. }
  16. if((*ptr & i) != 0) {
  17. crc = crc ^ 0x1021;
  18. }
  19. }
  20. ptr++;
  21. }
  22. return crc;
  23. }
  24. #include <stdio.h>
  25. int main()
  26. {
  27. char buf[] = {0x31, 0x14, 0x15, 0x92, 0x66};
  28. printf("%d\n", get_CRC(buf, 5));
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1905634707