I have a value B that I want to set if a variable A = 1.

I know how to create the if statement by applying an AND gate on a 1 constant and A, but how do I set B within that if statement using logic gates?

  • 5
    \$\begingroup\$ You seem to be jumbling up programming and logic gates. Please edit to give some context to the problem and then read it out loud to yourself before pressing submit. What is the big picture here? Are you asking how an AND gate works? The word set implies a latching action. \$\endgroup\$
    – Transistor
    Jan 27, 2021 at 22:09
  • \$\begingroup\$ Logic gates don't have if statements or "setting" \$\endgroup\$
    – user253751
    Jul 2, 2021 at 8:36

1 Answer 1


You have not mentioned what happens when A = 0. Should B hold the previous value? If that is the case, you need a latch or a Flip-Flop.

If all you want to do is set B when A = 1, why don't you directly connect B to A?

You can also use a buffer (2 NOT gates in series) to connect B to A.

When A = 1, B will be set to 1.

When A = 0, B will be set to 0.


Not the answer you're looking for? Browse other questions tagged or ask your own question.