Source Code : Compressing Streams: Parity Checksum

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Compressing Streams: Parity Checksum

         

import java.util.zip.Checksum;

public class ParityChecksum implements Checksum {
  long checksum = 0;

  public void update(int b) {
    int numOneBits = 0;
    for (int i = 1; i < 256; i *= 2) {
      if ((b & i) != 0)
        numOneBits++;
    }
    checksum = (checksum + numOneBits) % 2;
  }

  public void update(byte data[], int offset, int length) {
    for (int i = offset; i < offset + length; i++) {
      this.update(data[i]);
    }
  }

  public long getValue() {
    return checksum;
  }

  public void reset() {
    checksum = 0;
  }
}

   
    
    
    
    
    
    
    
    
  

Thank with us