2 input one output

So hello i am making a calculator in binary. I need help making something like this: when input 1 and 2 is high then turn output to high but if only one input is high the output is low like a AND-gate. I need little help. Thank you for help.

Use a compound if statement with a logic AND operator && as well as or operator ||

if ( (A == 1 && B == 0) || (A == 0 && B == 1) ) // now do your stuff

hippi97:
So hello i am making a calculator in binary. I need help making something like this: when input 1 and 2 is high then turn output to high but if only one input is high the output is low like a AND-gate. I need little help. Thank you for help.

Well in pseudo code:

If (input1 && input2)
{
digitalWrite(outputpin, HIGH);
}
else
{
digitalWrite(outputpin, LOW);
}

Couldn’t you use bitwise operators:

digitalWrite(outputPin, (digitalRead(inputPin1) & digitalRead(inputPin2));

retrolefty:

hippi97:
So hello i am making a calculator in binary. I need help making something like this: when input 1 and 2 is high then turn output to high but if only one input is high the output is low like a AND-gate. I need little help. Thank you for help.

Well in pseudo code:

If (input1 && input2)
{
digitalWrite(outputpin, HIGH);
}
else
{
digitalWrite(outputpin, LOW);
}

Thank you. This is what i needed. :slight_smile: