q-m.h

来自「by Quine and McCluskey」· C头文件 代码 · 共 51 行

H
51
字号
typedef enum {complemented, uncomplemented, doesntappear}TRIT;
typedef TRIT[16] CUBE;			// Represent a single product term weth up to 16 variables

# define MAX_VARS 16			// Max # of variables in a product term
typedef unsigned short WORD;	// Use 16-bit words
struct cube
{
	WORD t;						// Bits 1 for uncomplemented variables.
	WORD f;						// Bits 1 for complemented variables.
};
typedef struct cube CUBE;
CUBE P1, P2, P3;				// Allocate three cubes for use by program.

int EqualCubes(CUBE C1, CUBE C2)// Returns true if C1 and C2 are identical.
{
	return ( (C1.t == C2.t) && (C1.f == C2.f) );
}

int Oneone(WORD w)				// Returns true if w has exactly one 1 bit.
{
	// Optimizing the speed of this routine is critical
	// and is left as an exercise for the hacker.
	int ones = 0;
	for (int b=0; b<MAX_VARS; b++)
	{
		if (w & 1)
		{
			ones++;
		}
		w = w>>1;
	}
	return ((ones==1));
}

int Combinable(CUBE C1, CUBE C2)
{
	// Returns true if C1 and C2 differ in only one variable,
	// which appears true in one and false in the other.
	WORD twordt, twordf;
	twordt = C1.t ^ C2.t;
	twordf = C1.f ^ C2.f;
	return ( (twordt==twordf) && (Oneone(twordt)) );
}

void Combine(CUBE C1, CUBE C2, CUBE *C3)
{
	//Combines C1 and C2 using theorem T10, and stores the
	// result in C3. Assumes Combinable(C1, C2) is true.
	C3->t = C1.t & C2.t;
	C3->f = C1.f & C2.f;
}

⌨️ 快捷键说明

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