home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Secrets / Secrets2.iso / Audio / WAV / MaplayP / _SETUP.1 / crc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-30  |  1.3 KB  |  44 lines

  1. /*  crc.cpp
  2.  
  3.     CRC error checking */
  4.  
  5. /*
  6.  *  @(#) crc.cc 1.5, last edit: 6/15/94 16:55:30
  7.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  8.  *  @(#) Berlin University of Technology
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #include "all.h"
  26. #include "crc.h"
  27.  
  28. // polynomial generator
  29. const uint16 Crc16::polynomial = 0x8005;
  30.  
  31. void Crc16::add_bits (uint32 bitstring, uint32 length)
  32. {
  33.   uint32 bitmask = 1 << (length - 1);
  34.   do
  35.      if (!(crc & 0x8000) ^ !(bitstring & bitmask))
  36.      {
  37.         crc <<= 1;
  38.         crc ^= polynomial;
  39.      }
  40.      else
  41.         crc <<= 1;
  42.   while (bitmask >>= 1);
  43. }
  44.