Diffrent result for CRC32 in c++ and java -


I am trying to calculate the CRC 32 checksum in C ++ but I'm still getting bad results

C ++ code:

  class CRC32 {public: CRC 32 () {unsigned int poly = 0xedb88320; Unsigned int temp = 0; For (unsigned int i = 0; i  gt; 1) ^ poly ; } And {temp> gt; = 1; }} Table [i] = temporary; }} Unsigned int computeChecksum (byte * bytes, size_t size) {unsigned int CRC = 0xffffffff; For (int i = 0; i & lt; size; ++ i) {byte index = (byte) (((CRC) and 0xff) ^ bytes [ii]); CRC = (unsigned integer) ((CRC & gt; 8) ^ Table [index]); } Return ~ CRC; } Private: unsigned int tables [256]; };  

This Java code works fine:

  private int stmCrc32 (byte bite 0 []) {CRC32 crc32 = new CRC32 (); Crc32.update (abyte0); Return (int) (- 1l ^ crack 32.getValue ()); }  

This example is a hex string of data (the result should be 190 9 660290):

  00: 00: 00: 00: 00: 00: 00: 00: 00: 00: 00: 00: 00: 00: 00: 00: 00: 01: 00: 12: 00: 59: 57: 52: 74: 61: 57: 34: 36: 59: 57: 52: 74: 61: 57: 34: 3d: 0d: 0a: 00: 00  

Two implementations appear evenly. You just missed the surrounding code in C ++, just do the same way that they did in Java (but may be silent), and the result would be the same.

  bytes of data [] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x12, 0x00, 0x59, 0x57, 0x52, 0x74, 0x61, 0x57, 0x34, 0x36, 0x59, 0x57, 0x52, 0x74, 0x61, 0x57, 0x34, 0x3 D, 0x0d, 0x0a , 0x00, 0x00}; CRC 32 CRC; Int Result = (Int) (- 1 L ^ Crack Conput Chekssm (data, Saikof (data)); Std :: cout & lt; & lt; Results & lt; & lt; std :: endl;  < / Pre> 

Result: 190 9 660290


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -