home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09964.iso / sound / mpw32-5s.zip / CRC.H < prev    next >
C/C++ Source or Header  |  1994-06-23  |  1KB  |  45 lines

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