Before I share the framework I want to introduce readers to some background information.
On Wolfram's MathWorld website, there is an entry titled "Boolean Function". There are atleast 16 shown. Each of them are defined by a list of truth values. 4 truth-values exist for each function. They run vertical. (This point forth let vertical mean column and horizontal mean row.)
An enumeration of possible states of two bits. (No columns are labeled.)
0|0
0|1
1|0
1|1
The left column will be the A column and the B column the right column.
A|B
0|0
0|1
1|0
1|1
Given two bits you essentially get these possibilities. "00", "01", "10", "11". A bit is a value storing either a 0 or a 1.
With a third column we can compare across all of them to infer if A is 0 or 1, and B is 0 or 1, what C will be.
After creating a third column it is labeled with a C.
A|B|C
0|0|
0|1|
1|0|
1|1|
A and B columns even have their own functions which will match-up exactly in column C.
Here is the WolfRam MathWorld page for reference:
http://mathworld.wolfram.com/BooleanFunction.html
Time for the source code! I created a namespace named "Boolioni". In it there is a data structure I call Column. 4 truth values, and technically you are accessing horizontally.
A list of things included in Boolioni:
+Convert a boolean function index to its string name
+Convert a column to its string name
+Print all the names of the boolean functions
+Convert a column to its boolean function index
+Convert a boolean function's string name to a boolean function index.
+Convert a boolean function's index to a column
+Convert a boolean function's name to a column
+Printout values of a column.
The source code.
http://codepad.org/tEl5Fur4
Before I share the framework I want to introduce readers to some background information.
On Wolfram's MathWorld website, there is an entry titled "Boolean Function". There are atleast 16 shown. Each of them are defined by a list of truth values. 4 truth-values exist for each function. They run vertical. (This point forth let vertical mean column and horizontal mean row.)
An enumeration of possible states of two bits. (No columns are labeled.)
0|0
0|1
1|0
1|1
The left column will be the A column and the B column the right column.
A|B
0|0
0|1
1|0
1|1
Given two bits you essentially get these possibilities. "00", "01", "10", "11". A bit is a value storing either a 0 or a 1.
With a third column we can compare across all of them to infer if A is 0 or 1, and B is 0 or 1, what C will be.
After creating a third column it is labeled with a C.
A|B|C
0|0|
0|1|
1|0|
1|1|
A and B columns even have their own functions which will match-up exactly in column C.
Here is the WolfRam MathWorld page for reference:
http://mathworld.wolfram.com/BooleanFunction.html
Time for the source code! I created a namespace named "Boolioni". In it there is a data structure I call Column. 4 truth values, and technically you are accessing horizontally.
A list of things included in Boolioni:
+Convert a boolean function index to its string name
+Convert a column to its string name
+Print all the names of the boolean functions
+Convert a column to its boolean function index
+Convert a boolean function's string name to a boolean function index.
+Convert a boolean function's index to a column
+Convert a boolean function's name to a column
+Printout values of a column.
The source code.
http://codepad.org/tEl5Fur4
On Wolfram's MathWorld website, there is an entry titled "Boolean Function". There are atleast 16 shown. Each of them are defined by a list of truth values. 4 truth-values exist for each function. They run vertical. (This point forth let vertical mean column and horizontal mean row.)
An enumeration of possible states of two bits. (No columns are labeled.)
0|0
0|1
1|0
1|1
The left column will be the A column and the B column the right column.
A|B
0|0
0|1
1|0
1|1
Given two bits you essentially get these possibilities. "00", "01", "10", "11". A bit is a value storing either a 0 or a 1.
With a third column we can compare across all of them to infer if A is 0 or 1, and B is 0 or 1, what C will be.
After creating a third column it is labeled with a C.
A|B|C
0|0|
0|1|
1|0|
1|1|
A and B columns even have their own functions which will match-up exactly in column C.
Here is the WolfRam MathWorld page for reference:
http://mathworld.wolfram.com/BooleanFunction.html
Time for the source code! I created a namespace named "Boolioni". In it there is a data structure I call Column. 4 truth values, and technically you are accessing horizontally.
A list of things included in Boolioni:
+Convert a boolean function index to its string name
+Convert a column to its string name
+Print all the names of the boolean functions
+Convert a column to its boolean function index
+Convert a boolean function's string name to a boolean function index.
+Convert a boolean function's index to a column
+Convert a boolean function's name to a column
+Printout values of a column.
The source code.
http://codepad.org/tEl5Fur4
Code:
#include <iostream>
using namespace std;
namespace Boolioni
{
struct Column
{
bool States [4];
friend bool operator== (Column &col1, Column &col2);
friend bool operator!= (Column &col1, Column &col2);
};
bool operator== (Column &col1, Column &col2)
{
return (col1.States[0] == col2.States[0] &&
col1.States[1] == col2.States[1] &&
col1.States[2] == col2.States[2] &&
col1.States[3] == col2.States[3]);
}
bool operator!= (Column &col1, Column &col2)
{
return !(col1 == col2);
}
std::string getNameOfIndex(unsigned int nIndex);
std::string getNameOfColumn(Column column);
void printFunctionNames();
unsigned int getIndexByColumn(Column column);
unsigned int getIndexByName(std::string strName);
Column getColumnByIndex(unsigned int nIndex);
Column getColumnByName(std::string strVal);
void printColumn(Column column);
std::string getNameOfIndex(unsigned int nIndex)
{
std::string strName;
switch(nIndex)
{
case 0:
{
strName = "FALSE";
}
break;
case 1:
{
strName = "AND";
}
break;
case 2:
{
strName = "A AND NOT B";
}
break;
case 3:
{
strName = "A";
}
break;
case 4:
{
strName = "NOT A AND B";
}
break;
case 5:
{
strName = "B";
}
break;
case 6:
{
strName = "XOR";
}
break;
case 7:
{
strName = "OR";
}
break;
case 8:
{
strName = "NOR";
}
break;
case 9:
{
strName = "XNOR";
}
break;
case 10:
{
strName = "NOT B";
}
break;
case 11:
{
strName = "A OR NOT B";
}
break;
case 12:
{
strName = "NOT A";
}
break;
case 13:
{
strName = "NOT A OR B";
}
break;
case 14:
{
strName = "NAND";
}
break;
case 15:
{
strName = "TRUE";
}
break;
}
return strName;
}
void printFunctionNames()
{
cout << "Displaying names of functions 0 through 15.." << endl;
for (unsigned int iii = 0; iii < 16; ++iii)
{
cout << "=====" << endl;
cout << iii << endl;
cout << getNameOfIndex(iii) << endl;
cout << "=====" << endl;
}
}
std::string getNameOfColumn(Column column)
{
std::string strName;
unsigned int nIndex = getIndexByColumn(column);
strName = getNameOfIndex(nIndex);
return strName;
}
unsigned int getIndexByColumn(Column column)
{
unsigned int nIndex = 0;
Column columnB;
while (columnB != column)
{
columnB = getColumnByIndex(nIndex);
++nIndex;
}
return nIndex;
}
unsigned int getIndexByName(std::string strName)
{
unsigned int nIndex = 0;
if (strName == "FALSE")
{
nIndex = 0;
}
else if (strName == "AND")
{
nIndex = 1;
}
else if (strName == "A AND NOT B")
{
nIndex = 2;
}
else if (strName == "A")
{
nIndex = 3;
}
else if (strName == "NOT A AND B")
{
nIndex = 4;
}
else if (strName == "B")
{
nIndex = 5;
}
else if (strName == "XOR")
{
nIndex = 6;
}
else if (strName == "OR")
{
nIndex = 7;
}
else if (strName == "NOR")
{
nIndex = 8;
}
else if (strName == "XNOR")
{
nIndex = 9;
}
else if (strName == "NOT B")
{
nIndex = 10;
}
else if (strName == "A OR NOT B")
{
nIndex = 11;
}
else if (strName == "NOT A")
{
nIndex = 12;
}
else if (strName == "NOT A OR B")
{
nIndex = 13;
}
else if (strName == "NAND")
{
nIndex = 14;
}
else if (strName == "TRUE")
{
nIndex = 15;
}
return nIndex;
}
Column getColumnByIndex(unsigned int nIndex)
{
Column column;
switch(nIndex)
{
case 0:
{
column.States[0] = 0;
column.States[1] = 0;
column.States[2] = 0;
column.States[3] = 0;
}
break;
case 1:
{
column.States[0] = 0;
column.States[1] = 0;
column.States[2] = 0;
column.States[3] = 1;
}
break;
case 2:
{
column.States[0] = 0;
column.States[1] = 0;
column.States[2] = 1;
column.States[3] = 0;
}
break;
case 3:
{
column.States[0] = 0;
column.States[1] = 0;
column.States[2] = 1;
column.States[3] = 1;
}
break;
case 4:
{
column.States[0] = 0;
column.States[1] = 1;
column.States[2] = 0;
column.States[3] = 0;
}
break;
case 5:
{
column.States[0] = 0;
column.States[1] = 1;
column.States[2] = 0;
column.States[3] = 1;
}
break;
case 6:
{
column.States[0] = 0;
column.States[1] = 1;
column.States[2] = 1;
column.States[3] = 0;
}
break;
case 7:
{
column.States[0] = 0;
column.States[1] = 1;
column.States[2] = 1;
column.States[3] = 1;
}
break;
case 8:
{
column.States[0] = 1;
column.States[1] = 0;
column.States[2] = 0;
column.States[3] = 0;
}
break;
case 9:
{
column.States[0] = 1;
column.States[1] = 0;
column.States[2] = 0;
column.States[3] = 1;
}
break;
case 10:
{
column.States[0] = 1;
column.States[1] = 0;
column.States[2] = 1;
column.States[3] = 0;
}
break;
case 11:
{
column.States[0] = 1;
column.States[1] = 0;
column.States[2] = 1;
column.States[3] = 1;
}
break;
case 12:
{
column.States[0] = 1;
column.States[1] = 1;
column.States[2] = 0;
column.States[3] = 0;
}
break;
case 13:
{
column.States[0] = 1;
column.States[1] = 1;
column.States[2] = 0;
column.States[3] = 1;
}
break;
case 14:
{
column.States[0] = 1;
column.States[1] = 1;
column.States[2] = 1;
column.States[3] = 0;
}
break;
case 15:
{
column.States[0] = 1;
column.States[1] = 1;
column.States[2] = 1;
column.States[3] = 1;
}
break;
}
return column;
}
Column getColumnByName(std::string strVal)
{
Column column;
unsigned int nIndex = getIndexByName(strVal);
column = getColumnByIndex(nIndex);
return column;
}
void printColumn(Column column)
{
cout << column.States[0] << ' ' << column.States[1] << ' ' << column.States[2] << ' ' << column.States[3] << endl;
}
}
int main()
{
Boolioni::Column column = Boolioni::getColumnByIndex(3);
Boolioni::printColumn(column);
char input [8];
cin >> input;
return 0;
}
On Wolfram's MathWorld website, there is an entry titled "Boolean Function". There are atleast 16 shown. Each of them are defined by a list of truth values. 4 truth-values exist for each function. They run vertical. (This point forth let vertical mean column and horizontal mean row.)
An enumeration of possible states of two bits. (No columns are labeled.)
0|0
0|1
1|0
1|1
The left column will be the A column and the B column the right column.
A|B
0|0
0|1
1|0
1|1
Given two bits you essentially get these possibilities. "00", "01", "10", "11". A bit is a value storing either a 0 or a 1.
With a third column we can compare across all of them to infer if A is 0 or 1, and B is 0 or 1, what C will be.
After creating a third column it is labeled with a C.
A|B|C
0|0|
0|1|
1|0|
1|1|
A and B columns even have their own functions which will match-up exactly in column C.
Here is the WolfRam MathWorld page for reference:
http://mathworld.wolfram.com/BooleanFunction.html
Time for the source code! I created a namespace named "Boolioni". In it there is a data structure I call Column. 4 truth values, and technically you are accessing horizontally.
A list of things included in Boolioni:
+Convert a boolean function index to its string name
+Convert a column to its string name
+Print all the names of the boolean functions
+Convert a column to its boolean function index
+Convert a boolean function's string name to a boolean function index.
+Convert a boolean function's index to a column
+Convert a boolean function's name to a column
+Printout values of a column.
The source code.
http://codepad.org/tEl5Fur4
Code:
#include <iostream>
using namespace std;
namespace Boolioni
{
struct Column
{
bool States [4];
friend bool operator== (Column &col1, Column &col2);
friend bool operator!= (Column &col1, Column &col2);
};
bool operator== (Column &col1, Column &col2)
{
return (col1.States[0] == col2.States[0] &&
col1.States[1] == col2.States[1] &&
col1.States[2] == col2.States[2] &&
col1.States[3] == col2.States[3]);
}
bool operator!= (Column &col1, Column &col2)
{
return !(col1 == col2);
}
std::string getNameOfIndex(unsigned int nIndex);
std::string getNameOfColumn(Column column);
void printFunctionNames();
unsigned int getIndexByColumn(Column column);
unsigned int getIndexByName(std::string strName);
Column getColumnByIndex(unsigned int nIndex);
Column getColumnByName(std::string strVal);
void printColumn(Column column);
std::string getNameOfIndex(unsigned int nIndex)
{
std::string strName;
switch(nIndex)
{
case 0:
{
strName = "FALSE";
}
break;
case 1:
{
strName = "AND";
}
break;
case 2:
{
strName = "A AND NOT B";
}
break;
case 3:
{
strName = "A";
}
break;
case 4:
{
strName = "NOT A AND B";
}
break;
case 5:
{
strName = "B";
}
break;
case 6:
{
strName = "XOR";
}
break;
case 7:
{
strName = "OR";
}
break;
case 8:
{
strName = "NOR";
}
break;
case 9:
{
strName = "XNOR";
}
break;
case 10:
{
strName = "NOT B";
}
break;
case 11:
{
strName = "A OR NOT B";
}
break;
case 12:
{
strName = "NOT A";
}
break;
case 13:
{
strName = "NOT A OR B";
}
break;
case 14:
{
strName = "NAND";
}
break;
case 15:
{
strName = "TRUE";
}
break;
}
return strName;
}
void printFunctionNames()
{
cout << "Displaying names of functions 0 through 15.." << endl;
for (unsigned int iii = 0; iii < 16; ++iii)
{
cout << "=====" << endl;
cout << iii << endl;
cout << getNameOfIndex(iii) << endl;
cout << "=====" << endl;
}
}
std::string getNameOfColumn(Column column)
{
std::string strName;
unsigned int nIndex = getIndexByColumn(column);
strName = getNameOfIndex(nIndex);
return strName;
}
unsigned int getIndexByColumn(Column column)
{
unsigned int nIndex = 0;
Column columnB;
while (columnB != column)
{
columnB = getColumnByIndex(nIndex);
++nIndex;
}
return nIndex;
}
unsigned int getIndexByName(std::string strName)
{
unsigned int nIndex = 0;
if (strName == "FALSE")
{
nIndex = 0;
}
else if (strName == "AND")
{
nIndex = 1;
}
else if (strName == "A AND NOT B")
{
nIndex = 2;
}
else if (strName == "A")
{
nIndex = 3;
}
else if (strName == "NOT A AND B")
{
nIndex = 4;
}
else if (strName == "B")
{
nIndex = 5;
}
else if (strName == "XOR")
{
nIndex = 6;
}
else if (strName == "OR")
{
nIndex = 7;
}
else if (strName == "NOR")
{
nIndex = 8;
}
else if (strName == "XNOR")
{
nIndex = 9;
}
else if (strName == "NOT B")
{
nIndex = 10;
}
else if (strName == "A OR NOT B")
{
nIndex = 11;
}
else if (strName == "NOT A")
{
nIndex = 12;
}
else if (strName == "NOT A OR B")
{
nIndex = 13;
}
else if (strName == "NAND")
{
nIndex = 14;
}
else if (strName == "TRUE")
{
nIndex = 15;
}
return nIndex;
}
Column getColumnByIndex(unsigned int nIndex)
{
Column column;
switch(nIndex)
{
case 0:
{
column.States[0] = 0;
column.States[1] = 0;
column.States[2] = 0;
column.States[3] = 0;
}
break;
case 1:
{
column.States[0] = 0;
column.States[1] = 0;
column.States[2] = 0;
column.States[3] = 1;
}
break;
case 2:
{
column.States[0] = 0;
column.States[1] = 0;
column.States[2] = 1;
column.States[3] = 0;
}
break;
case 3:
{
column.States[0] = 0;
column.States[1] = 0;
column.States[2] = 1;
column.States[3] = 1;
}
break;
case 4:
{
column.States[0] = 0;
column.States[1] = 1;
column.States[2] = 0;
column.States[3] = 0;
}
break;
case 5:
{
column.States[0] = 0;
column.States[1] = 1;
column.States[2] = 0;
column.States[3] = 1;
}
break;
case 6:
{
column.States[0] = 0;
column.States[1] = 1;
column.States[2] = 1;
column.States[3] = 0;
}
break;
case 7:
{
column.States[0] = 0;
column.States[1] = 1;
column.States[2] = 1;
column.States[3] = 1;
}
break;
case 8:
{
column.States[0] = 1;
column.States[1] = 0;
column.States[2] = 0;
column.States[3] = 0;
}
break;
case 9:
{
column.States[0] = 1;
column.States[1] = 0;
column.States[2] = 0;
column.States[3] = 1;
}
break;
case 10:
{
column.States[0] = 1;
column.States[1] = 0;
column.States[2] = 1;
column.States[3] = 0;
}
break;
case 11:
{
column.States[0] = 1;
column.States[1] = 0;
column.States[2] = 1;
column.States[3] = 1;
}
break;
case 12:
{
column.States[0] = 1;
column.States[1] = 1;
column.States[2] = 0;
column.States[3] = 0;
}
break;
case 13:
{
column.States[0] = 1;
column.States[1] = 1;
column.States[2] = 0;
column.States[3] = 1;
}
break;
case 14:
{
column.States[0] = 1;
column.States[1] = 1;
column.States[2] = 1;
column.States[3] = 0;
}
break;
case 15:
{
column.States[0] = 1;
column.States[1] = 1;
column.States[2] = 1;
column.States[3] = 1;
}
break;
}
return column;
}
Column getColumnByName(std::string strVal)
{
Column column;
unsigned int nIndex = getIndexByName(strVal);
column = getColumnByIndex(nIndex);
return column;
}
void printColumn(Column column)
{
cout << column.States[0] << ' ' << column.States[1] << ' ' << column.States[2] << ' ' << column.States[3] << endl;
}
}
int main()
{
Boolioni::Column column = Boolioni::getColumnByIndex(3);
Boolioni::printColumn(column);
char input [8];
cin >> input;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire