fork(3) download
  1. // CRC.cpp : Example program for computing slide label CRC.
  2. // Copyright 2003 Cytyc Corp. All rights reserved.
  3.  
  4.  
  5. #include <stdio.h>
  6.  
  7. #define SLIDE_ID_LEN 11 // Length of slide ID
  8.  
  9. // This function computes and returns the CRC associated with the slideIDString input
  10. // argument.
  11. //
  12. unsigned char computeCrc(char *slideIdString)
  13. {
  14. unsigned char Local8BitPoly = 0x025;
  15. unsigned char crcTable[256];
  16. int i,j;
  17. unsigned char crc = 0;
  18.  
  19. // Generate CRC table
  20. unsigned char crc_accum;
  21. for(i=0; i<256; i++)
  22. {
  23. crc_accum = (unsigned char) i;
  24.  
  25. for(j=0; j<8; j++)
  26. { // If lead 1 then XOR to divide else move on.
  27. if(crc_accum & 0x80)
  28. crc_accum = (crc_accum << 1) ^ Local8BitPoly;
  29. else
  30. crc_accum = (crc_accum << 1);
  31. }
  32. crcTable[i] = crc_accum; // Update next item in table
  33. }
  34.  
  35.  
  36. // calculate the CRC
  37. for(j=0; j < SLIDE_ID_LEN; j++)
  38. {
  39. i = ((crc) ^ slideIdString[j]) & 0xff;
  40. crc = (crc << 8) ^ crcTable[i];
  41. }
  42.  
  43. return crc;
  44. }
  45.  
  46.  
  47. // This main program provides an example of how to use the computeCrc function.
  48. // In this example, the CRC's are computed and displayed for a range of 25 ID's starting
  49. // with the ID value of "140180001".
  50. //
  51. int main(int argc, char* argv[])
  52. {
  53. long id = 14222300;
  54. long y_id = 11;
  55. char idstring[SLIDE_ID_LEN+1];
  56. int i;
  57.  
  58. // Generate CRC for 25 values
  59. for (i=0; i < 11; i++, id++)
  60. {
  61. sprintf(idstring, "%02ld%09ld", y_id, id);
  62. printf("%s %03d\n", idstring, computeCrc(idstring));
  63. }
  64.  
  65. return 0;
  66. }
  67.  
  68.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty