Path: blob/main/src/lwjgl/java/javazoom/jl/decoder/Crc16.java
8650 views
/*1* 11/19/04 : 1.0 moved to LGPL.2*3* 02/12/99 : Java Conversion by E.B , [email protected]4*5* @(#) crc.h 1.5, last edit: 6/15/94 16:55:326* @(#) Copyright (C) 1993, 1994 Tobias Bading ([email protected])7* @(#) Berlin University of Technology8*-----------------------------------------------------------------------9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU Library General Public License as published11* by the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU Library General Public License for more details.18*19* You should have received a copy of the GNU Library General Public20* License along with this program; if not, write to the Free Software21* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.22*----------------------------------------------------------------------23*/24package javazoom.jl.decoder;2526/**27* 16-Bit CRC checksum28*/29public final class Crc1630{31private static short polynomial=(short)0x8005;32private short crc;3334/**35* Dummy Constructor36*/37public Crc16()38{39crc = (short) 0xFFFF;40}4142/**43* Feed a bitstring to the CRC calculation (0 < length <= 32).44*/45public void add_bits (int bitstring, int length)46{47int bitmask = 1 << (length - 1);48do49if (((crc & 0x8000) == 0) ^ ((bitstring & bitmask) == 0 ))50{51crc <<= 1;52crc ^= polynomial;53}54else55crc <<= 1;56while ((bitmask >>>= 1) != 0);57}5859/**60* Return the calculated checksum.61* Erase it for next calls to add_bits().62*/63public short checksum()64{65short sum = crc;66crc = (short) 0xFFFF;67return sum;68}69}707172