⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gf2.h

📁 压缩文件中是Error Correction Coding - Mathematical Methods and Algorithms(Wiley 2005)作者:(Todd K. Moon )的配
💻 H
字号:
// GF2.h -- GF(2) numbers// Created by Todd K. Moon// Copyright 2004 by Todd K. Moon// Permission is granted to use this program/data// for educational/research only#ifndef GF2_H#define GF2_H#include <iostream>using namespace std;class GF2 {protected:   unsigned char v;		  // the value of the element (in vector form)   static void gferror(char *s) {	  cerr << s;   } // print an error messagepublic:   // Constructors   GF2(const GF2& newnum) { v = newnum.v;}	// assignment    GF2(const int newv) { v = newv;};                                 // pass in a number in vector representation   GF2(void) { v = 0;};		 // default constructor 0 element)   ~GF2() {};				// destructor   // Functions to get member information   int getv(void) const { return v; };    // ***********************************************************************   //                   the overloaded operators   // ***********************************************************************   GF2& operator+=(const GF2 &a) { v ^= a.v;  return *this; }   GF2& operator-=(const GF2 &a) { v ^= a.v;  return *this; }   GF2& operator*=(const GF2 &a) {	  v &= a.v;	  return *this;   }   GF2& operator/=(const GF2 &a) {	  if(a.v == 0) {		 gferror("Division by zero in Galois field arithmetic\n");	  }	  return *this;   }   GF2& operator^=(const int exp) {	  return *this;   }	// unary -   GF2 operator-() const { return *this; }   GF2 operator+(const GF2 &b) const {return GF2(v^b.v);}   GF2 operator-(const GF2 &b) const {return GF2(v^b.v);}   GF2 operator*(const GF2 &b) const {	  GF2 temp(v & b.v);	  return temp;   };   GF2 operator/(const GF2 &b) const {	  if(b.v == 0) {		 gferror("Division by zero in Galois field arithmetic\n");	  }	  else {		 GF2 temp(v & b.v);		 return temp;	  }   }   // exponentiation operator: watch the precedence!!   // const int e is changed to int e because there is no   // way the variable location the user supplies for e is   // going to be modified.  The function is more efficient   // if it can modify its own copy of e.   GF2 operator^(const int e) const {	  return *this;   }   int operator==(const GF2 &b) const {return (v == b.v);}   int operator!=(const GF2 &b) const {return (v != b.v);}   friend ostream& operator<<(ostream &os, const GF2 &a) {	  return os << int(a.v);   }};inline GF2 operator+(const int a, const GF2 b) { return b+a;}inline GF2 operator-(const int a, const GF2 b) { return b+a;}inline GF2 operator*(const int a, const GF2 b) { return b*a;}inline GF2 operator/(const int a, const GF2 b) { return GF2(a)/b;}inline GF2 operator==(const int a, const GF2 b) { return b==a;}inline GF2 operator!=(const int a, const GF2 b) { return b!=a;}#endif/*Local Variables:compile-command: "g++ -c -g GF2.cc"End:*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -