GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java/Others/crc32.java at master · rpendrick/Java

Expand file tree

/

crc32.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
27 lines (22 loc) · 902 Bytes
/

crc32.java

Copy path

File metadata and controls

27 lines (22 loc) · 902 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.BitSet;
//Generates a crc32 checksum for a given string or byte array
public class crc32 {
public static void main(String[] args) {
System.out.println(Integer.toHexString(crc32("Hello World")));
}
public static int crc32(String str) {
return crc32(str.getBytes());
}
public static int crc32(byte[] data) {
BitSet bitSet = BitSet.valueOf(data);
int crc32 = 0xFFFFFFFF; //initial value
for(int i=0;i<data.length*8;i++) {
if(((crc32>>>31)&1) != (bitSet.get(i)?1:0))
crc32 = (crc32 << 1) ^ 0x04C11DB7; //xoring with polynomial
else
crc32 = (crc32 << 1);
}
crc32 = Integer.reverse(crc32); //result reflect
return crc32 ^ 0xFFFFFFFF; //final xor value
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.