Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

bit_scrambler.h

Go to the documentation of this file.
00001 /*
00002  * SPUC - Signal processing using C++ - A DSP library
00003  * 
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2, or (at your option)
00007  * any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 #ifndef BSCRAM
00019 #define BSCRAM
00020 namespace SPUC {
00029 
00030 class bit_scrambler {
00031  public:
00032         unsigned long g;
00033         long span;
00034 
00035  public:
00036         unsigned long u;
00037         bit_scrambler(long gen=0x48, long bits=7, long uinit=-1) 
00038                 : g(gen), span(bits), u(uinit) {;}
00039         void reset() { u=~0; }
00040         bool scramble(bool data_in) {
00041                 bool res = xor_bits(u&g);
00042                 u <<= 1;
00043                 u += res;
00044                 return(data_in ^ res);
00045         }
00047         bool xor_bits(long x) {
00048                 bool c=0;
00049                 for (int i =0;i<span;i++) {
00050                         c ^= (x & 0x01);
00051                         x >>= 1;
00052                 }
00053                 return(c);
00054         }
00055 };
00056 } // namespace SPUC
00057 #endif

Generated on Fri Sep 16 11:02:17 2005 for spuc by  doxygen 1.4.4