📄 crc32.java
字号:
/************************************************************************* * Compilation: javac CRC32.java CharStdIn.java * Execution: java CRC32 < data.txt * * Reads in a sequence of bytes and prints out their 32 bit * Cylcic Redundancy Check (CRC32 or Ethernet / AAL5 or ITU-TSS). * * 0 1 2 4 5 7 8 10 11 12 16 22 23 26 32 * *************************************************************************/public class CRC32 { public static void main(String[] args) { int crc = 0xFFFFFFFF; // initial contents of LFBSR while (!CharStdIn.isEmpty()) { char c = CharStdIn.readChar(); // read 8 bits one at a time for (int i = 0; i < 8; i++) { boolean c31 = ((crc >>> 31 & 1) == 1); boolean bit = ((c >>> (7 - i) & 1) == 1); crc <<= 1; /************************************************************** * Uses irreducible polynomial: * 1 + x + x^2 + x^4 + x^5 + x^7 + x^8 + * x^10 + x^11 + x^12 + x^16 + x^22 + x^23 + x^26 * * 0000 0100 1100 0001 0001 1101 1011 0111 * 0 4 C 1 1 D B 7 **************************************************************/ if (c31 ^ bit) crc ^= 0x04C11DB7; } } System.out.println("CRC32 = " + crc); System.out.println("CRC32 = " + Integer.toHexString(crc)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -