Java CRC Calculate calculateCrc16(byte[] buffer)

Here you can find the source of calculateCrc16(byte[] buffer)

Description

calculate Crc

License

Open Source License

Declaration

public static short calculateCrc16(byte[] buffer) 

Method Source Code

//package com.java2s;
/**//w w w. j a v  a 2  s .  co m
 * Confidential Information.
 * Copyright (C) 2007-2009 Eric Link, All rights reserved.
 * PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 **/

public class Main {
    private static final short[] crcTable = new short[256];

    public static short calculateCrc16(byte[] buffer) {
        return calculateCrc16(buffer, 0, buffer.length);
    }

    public static short calculateCrc16(byte[] buffer, int offset, int length) {
        short crc = (short) 0xffff; //x25 CCITT-CRC16 seed
        for (int i = 0; i < length; i++) {
            crc = (short) (crcTable[(buffer[i + offset] ^ (crc >>> 8)) & 0xff] ^ (crc << 8));
        }
        return crc;
    }
}

Related

  1. calcCRC(int crc, byte[] bytes, int start, int len)
  2. calculateCRC(byte[] buff, int count)
  3. calculateCRC(byte[] data, int offset, int len)
  4. calculateCRC(String digitsToCheck)
  5. calculateCRC(String id)
  6. calculateCRC32(byte[] buf, int off, int len)
  7. computeCRC(InputStream in)
  8. computeCRC32(File file)
  9. computeCrc32(InputStream is)