fi.helsinki.cs.ohtu.mpeg2.util
Class CRC16

java.lang.Object
  extended by fi.helsinki.cs.ohtu.mpeg2.util.CRC16
All Implemented Interfaces:
java.util.zip.Checksum

public class CRC16
extends java.lang.Object
implements java.util.zip.Checksum

A class for computing CRC-16 checksums. The generator polynomial is x^16 + x^15 + x^2 + 1.


Field Summary
private static int CRC16_POLY
           
private  int reg
           
 
Constructor Summary
CRC16()
          Creates a new CRC-16 instance.
 
Method Summary
 long getValue()
          Returns CRC-16 value.
 void reset()
          Resets CRC-16 to the initial value.
 void update(byte[] b)
          Updates CRC-16 with specified array of bytes.
 void update(byte[] b, int off, int len)
          Updates CRC-16 with specified array of bytes.
 void update(int b)
          Updates CRC-16 with specified byte.
 void updateBit(int b)
          Updates CRC-16 with specified bit.
 void updateBits(int word, int len)
          Updates CRC-16 with specified bits.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CRC16_POLY

private static final int CRC16_POLY
See Also:
Constant Field Values

reg

private int reg
Constructor Detail

CRC16

public CRC16()
Creates a new CRC-16 instance.

Method Detail

getValue

public long getValue()
Returns CRC-16 value.

Specified by:
getValue in interface java.util.zip.Checksum
Returns:
The current CRC-16 checksum value

reset

public void reset()
Resets CRC-16 to the initial value.

Specified by:
reset in interface java.util.zip.Checksum

update

public void update(byte[] b,
                   int off,
                   int len)
Updates CRC-16 with specified array of bytes.

Specified by:
update in interface java.util.zip.Checksum
Parameters:
b - The array of bytes to update the checksum with
off - The start offset of the data
len - The number of bytes to use

update

public void update(byte[] b)
Updates CRC-16 with specified array of bytes.

Parameters:
b - The array of bytes to update the checksum with

update

public void update(int b)
Updates CRC-16 with specified byte.

Specified by:
update in interface java.util.zip.Checksum
Parameters:
b - The byte to update the checksum with

updateBit

public void updateBit(int b)
Updates CRC-16 with specified bit.

Parameters:
b - The bit to update the checksum with

updateBits

public void updateBits(int word,
                       int len)
Updates CRC-16 with specified bits.

Parameters:
word - The bits to update the checksum with
len - The number of the least significant bits to use