Here you can find the source of crc16_get(byte aby[], int nOffset, int nLength)
public static int crc16_get(byte aby[], int nOffset, int nLength)
//package com.java2s; /**************************************************************************** This file is part of TIImageTool.//from w w w . j a v a 2 s .c o m TIImageTool is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. TIImageTool is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with TIImageTool. If not, see <http://www.gnu.org/licenses/>. Copyright 2011 Michael Zapf www.mizapf.de ****************************************************************************/ public class Main { public static int crc16_get(byte aby[], int nOffset, int nLength) { return crc16_get(aby, nOffset, nLength, 0xffff); } public static int crc16_get(byte aby[], int nOffset, int nLength, int init) { // Big-endian, x^16+x^12+x^5+1 = (1) 0001 0000 0010 0001 = 0x1021 int rem = init; int n = 16; // A popular variant complements rem here int i; int j; for (i = 0; i < nLength; i++) { rem = (rem ^ (aby[i + nOffset] << (n - 8))); for (j = 0; j <= 7; j++) { if ((rem & 0x8000) == 0x8000) { rem = ((rem << 1) ^ 0x1021); } else { rem = (rem << 1); } } } // A popular variant complements rem here return (rem & 0xffff); } }