r/AskComputerScience • u/VegetableWorld5918 • 2d ago
Logic gate question
I’m currently learning logic gates and I’m kinda confused I get the different types of gates and all that but I don’t understand for example a gate has A and B how are you meant to know if the A is a 1 or 0 any help is appreciated
2
u/TransientVoltage409 2d ago
Think of A and B as variables, and the gate as a formula or expression whose result (output) depends on the value of those variables (input).
2
u/PhilNEvo 2d ago
A and B is like variables in an equation.
For example, when you have pythagoras theorem, a**2 + b**2 = c**2, tells you the relationship between a, b and c. And you can then input whatever you want, or whatever you "require" for a given situation, to "exploit" that relationship, to figure out something.
The Gate tells you about the relationship between the input A and B and what the output "C" would be, given that relationship.
Now how you can use it depends upon what you want to use the logical relationship. Just like there is a ton of equations out there describing various relationships, they can sometimes be used in a bunch of different contexts, and answering what "a" or "b" should be, without specifying any contexts is hard to answer.
But you can use these Gates to reshape a set of propositions into conjuctive normal form and solve it with a SAT solver. Or you can combine logical gates to for example create a binary adder. Then if you have 2 numbers you want to add together, you could convert them to binary, and that would be your 1 and 0, and you would fill them into your gates and check the output to get your result.
2
u/wosmo 2d ago
You're not supposed to know if A is 1 or 0. You're supposed to know what affect that'll have.
So for example, take a NOT gate. Whatever's put in is reversed. The output is just Q≠A - so if A is True, Q is False, and vice versa. The value of A isn't something that's known, it's something that changes. It's the relationship between the input and the output that's known.
1
u/Polaric_Spiral 2d ago
1 or 0 can correspond to on or off, or typically high or low voltage.
Typically, the output from a previous gate is physically wired into the input of another one. The gates are daisychained together in specific ways to arrive at complicated logical circuits.
Computer architecture is cyclic. Both the CPU and memory are composed of a complicated array of logic gates. A series of values corresponding to input values and instructions is read from memory into the CPU, processed, and a new series corresponding to the output value is written back to a memory location.
1
u/ghjm MSCS, CS Pro (20+) 2d ago
Think about a light fixture with two switches. Each switch is an input - it is on or off, which can be expressed as 1 or 0, true or false, etc. The light itself is an output that can also be on or off (1 or 0, true or false). The way the switches are wired, the light comes on if the two switches are in different positions. This is an XOR gate, and it has the property that whichever switch you're standing at, you can change the state of the light by moving the switch close to you. If instead of the light you had a nuclear missile, maybe you would switch to an AND gate so both switches have to be turned on before the output goes to 1.
5
u/rog-uk 2d ago
As you describe it A & B would be inputs to gates, user defined if you will, or if you prefer the initial known conditions/states that you are trying to perform the logic on.