logic gates functions

this a four logic gate contains the logic : AND, OR and NOT, and it suppose to take four in put and divide them into to numbers and add them together like this : the input is ( 1 0 1 1 ) divide them to ( 10 + 11 ) equal to ( 0 1 0 1 ) and convert it to decimal which equivalent to ( 2 + 3 ) equal to ( 5 )
anyone know something please do ...



[#include<iostream>
#include<cmath>
#include<string>


using namespace std;

double binary_decimal(int bin1, int bin2, int bin3, int bin4);
bool gate1(bool input1, bool input2, bool &innergate1output);
bool gate2(bool input3, bool input4, bool &innergate1output);
bool gate3(bool input3, bool input4, bool innergate1output);
bool gate4(bool input4, bool outputgate2);

int main()
{

int x = 0;
bool bin1 = 0, bin2 = 0, bin3 = 0, bin4 = 0;
cout << "Enter the first binary number: " << endl;
cin >> bin3 >> bin1 >> bin4 >> bin2;
int decimal = 0;


if (bin1 == 0 || bin1 == 1 && bin2 == 0 || bin2 == 1 && bin3 == 0 || bin3 == 1 && bin4 == 0 || bin4 == 1)
{
gate1(bin1, bin2, bin3);
gate2(bin1, bin2, bin3);
gate3(bin1, bin2, bin3);
gate4(bin1, bin2);
binary_decimal(bin1, bin2, bin3, bin4);


}

else
cout << "Wrong binary number try again";

cout << bin1 << bin2 << bin3 << bin4 << " in binary , " << binary_decimal(bin1, bin2, bin3, bin4) << " in decimal" << endl;


system("pause");
return 0;
}


bool gate1(bool input1, bool input2, bool &innergate1output)
{
bool temp1 = input1 || input2;
bool temp2 = input1 && input2;
innergate1output = temp2;
bool temp3 = !temp2;
bool outputgate1 = temp1&&temp3;
bool bin1 = outputgate1;

return outputgate1;
}

bool gate2(bool input3, bool input4, bool &innergate1output)
{
bool temp1 = innergate1output && input3;
bool temp2 = !temp1;
bool temp3 = temp2 && innergate1output;
bool temp4 = input3 && temp2;
bool outputgate2 = temp3 || temp4;



return outputgate2;
}

bool gate3(bool input3, bool input4, bool innergate1output)
{
bool temp1 = innergate1output && input3;
bool temp2 = input4 && innergate1output;
bool temp3 = input4 && input3;
bool temp4 = temp2 || temp3;
bool outputgate3 = temp1 || temp4;
bool bin3 = outputgate3;

return outputgate3;
}

bool gate4(bool input4, bool bin2)
{
bool temp1 = input4 && bin2;
bool temp2 = !temp1;
bool temp3 = temp2 && bin2;
bool temp4 = temp2 && input4;
bool outputgate4 = temp3 || temp4;
bool bin4 = outputgate4;

return outputgate4;
}

double binary_decimal(int bin1, int bin2, int bin3, int bin4) /* Function to convert binary to decimal.*/
{
double temp1 = bin4*pow(2, 0);
double temp2 = bin3*pow(2, 1);
double temp3 = bin2*pow(2, 2);
double temp4 = bin1*pow(2, 3);
double result = temp1 + temp2 + temp3 + temp4;

return result;
}
][]
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/195539/
Topic archived. No new replies allowed.