# How does a computer recognize 0s and 1s? [closed]

I'm not too sure if this is the correct site for this but anyway, I heard that whenever a computer program is compiled, it is turned into 0s and 1s. But how does a computer recognize 0s and 1s? A computer is electrical and electricity can't read. So how does a computer read 0s and 1s?

• I'm sure this is a duplicate of something, but I can't find it.. Aug 4, 2016 at 23:38
• Google: What is a digital circuit; Google: How a digital circuit works; Google: How to make a full adder; Google: How to make an ALU; Aug 4, 2016 at 23:52
• I don't see anything wrong with this question. The OP just doesn't phrase the question well. And @user2943160, it really isn't too broad, imho, since the answer to both is the same. In all cases, the 0/1 is represented as a voltage somewhere. Unless it is on a HDD in which case it is represented as a magnetic dipole which is converted into a voltage when read. Aug 5, 2016 at 0:23
• Code: The Hidden Language of Computer Hardware and Software by Petzold Aug 5, 2016 at 1:00
• I have two concerns with this question; 1 it shows no evidence of research or effort to understand, and 2, it is worded in such a way that it seems too broad to give a succinct, clear answer. Clearly, computers work. So " I heard that whenever a computer program is compiled, it is turned into 0s and 1s" is true. However phrases like "But how does a computer recognize 0s and 1s? A computer is electrical and electricity can't read." seem to be a 'fundamental misunderstanding' problems. Please reword to ask a simpler focused question. Please read the help center to understand how to ask good questions Aug 5, 2016 at 1:17

When people say 1s and 0s, what we're really referring to are logic levels, where a 0 refers to a 'low' level and a 1 refers to a 'high' level. Since these are just voltage levels, the computer can recognize and operate on these natively.

Also, a computer program is usually stored as 0s and 1s before compiling as well, as everything on your computer will be stored that way. However, after compiling, you will get a file filled with what is called machine code. Machine code is a list of binary instructions (as opposed to text like the original source code) that can be directly interpreted by the circuitry in the processor.

• A similar question is asked here. It has a great answer by @jonk. electronics.stackexchange.com/questions/249064/… Aug 4, 2016 at 22:53
• okay, but it's impossible to program voltage, so whenever the OS receives the request for a file to be executed, how does it send out the voltages required to run the program?
– Max
Aug 4, 2016 at 23:04
• The 1's and 0's that we think about are stored in the computer's memory as voltages. A "1" is usually a voltage near the system's power supply voltage, while a "0" is a voltage near ground. Aug 4, 2016 at 23:11
• @Max We're talking about the hardware level, right? At the hardware level there is no such thing as an OS, there is only a CPU that sends out voltages because it's an electrical device. Aug 5, 2016 at 1:10
• @Max And then, once we've established that a CPU is an electrical device that sends out voltages and receives voltages, then we can talk about the CPU running programs, and figure out what "running a program" even means in terms of voltages. After that, we can define what an operating system is and how it's different from a "normal" program. Aug 5, 2016 at 1:12

When HUMANS look at ones and zeros, we see "1" or "0" on a screen, or printed on paper, or even as a LED that is dark or lit. But what a COMPUTER "sees" as a logical zero is zero volts, and a logical one as some predetermined voltage like 5V. (Lower in modern CPUs, etc. but never zero.)

In exactly the same manner as a light switch on the wall. A HUMAN sees the light switch physically in one position or the other, but the light either "sees" the mains power and lights up, or it "sees" zero power and cannot light up.

You say "it is impossible to program a voltage". But that is not correct. That is EXACTLY what you are programming. It comes down to 0V (logic zero) or 5V (logic one).

The way I understand it is: A computer has components that recognize the presence of + voltage. if there is + voltage it's 1 if there isn't +voltage it's 0.

• Physical binary encoding is much more complicated than positive/zero voltage. Aug 5, 2016 at 0:06
• 0 and 1 are very, very rarely encoded by a presence or absence of a voltage. For all practical purpose 0 and 1 are not encoded this way. 0 and 1 may be encoded by a + voltage and 0 volts, but 0V is not the absence of a voltage because it can sink current. Aug 5, 2016 at 1:08
• Actually, 0v is by definition the absence of voltage, because voltage is a potential difference. Don't confuse voltage and current... Digital inputs typically have a tolerance where something up to the Vil threashold will read as a zero, but the intent and what CMOS outputs come close to achieving really is quite close to the presence or absence of voltage. Of course there are also more complicated logic standards, including bipolar, inverted, and differential standards. Aug 5, 2016 at 2:48

Transistors can be used two ways, we know about them being able to amplify things, feed in a signal of voltage X you get "out" a signal of voltage X*Y. But that is the linear region. It can only go as high or as low as the power supply or voltage rails. So you can also use them as switches, forcing them through the linear region and slamming into either the high or low rail. Take a couple transistors, add some other elementary components and you can electrically build AND, OR, NOT, etc circuits. And from that you can wire up any kind of boolean equation you want. Now take things that oscillate, crystals or just using the nature of the speed of the electrons through a material and feedback, you can create a "one", "zero", "one"..."clock". feed the clock into the boolean equations and you can build computers. Play with feedback some more and/or take advantage of electrical components like capacitors or magnetics and you can store ones and zeros to be retrieved later. The storing and retrieving are nothing more than boolean equations built by elementary logic gates made up of transistors and other elementary components.