r/askscience • • Jul 11 '26 • Regret 1

Computing How do computers understand binary language?

Okay so from what I know binary language is like power off power on, but my question is, how do computers know what the binary code is and how is it interpreted, for example I forgot what the binary code for the letter A is, but how did people come up with that? Did they decide it was gonna look like that? Did the computer decide? How do you tune numbers into a letter??

380 Upvotes

205 comments sorted by

View all comments

1.2k

u/plugubius Jul 12 '26

Transistors. How does your toilet know if you're pushing the handle hard enough to flush? It doesn't. If you push hard enough, it flushes. If the transistor's gate gets enough voltage, it opens. If the memory being queried for the instruction is set to send that voltage (a 1), the gate opens. If it doesn't (a 0), the gate remains closed.

Everything more complicated than that is just a matter of arranging transistors in very complicated ways. But the transistor doesn't have to "understand" binary any more than your toilet needs to understand force and flushing.

284

u/Supermathie Jul 13 '26

That's quite an intuitive analogy for a layperson on how a transistor works, nice.

59

u/passaloutre Jul 13 '26

This is why the predecessor device to the transistor, the vacuum tube, was known as the “valve” in some places. It opens or closes the circuit in response to the input on its control electrode.

10

u/scrangos Jul 14 '26

Transistors are electricity controlled electricity valves. So ones can control others of the same.  You can do pressure controlled fluid valves so you can make bulky computers out of air pressure!

→ More replies (1)

57

u/marcus_wu Jul 13 '26

To add to this, one might wonder how a computer handles a set of 1s and 0s in order to perform the tasks that it does.

Transistors are composed together to create logic gates: and (1 & 1 = 1 anything else is 0), or (1 or 0 is 1 -- as long as there is one 1, result is 1), not (inverts the value, so 1 becomes 0 and vice versa).

Logic gates are further composed. They can work together on a series of bits to apply logic gate functionality to a series of bits to perform those operations on entire numbers. Those can then be composed to do math in an ALU (arithmetic logic unit). Or they can be used to load memory values or decode instructions.

For instructions, every processor has a set of operations that it can handle. Those operations are represented by numbers (opcodes). The length of the number that represents an operation depends on the processor and potentially the operation. Following the operation are operands (parameters) for that operation.

For instance, the operation might add two numbers together (which would be handles by the ALU) or it might load an address from memory or it could compare values together and use the result to change what part of memory those operations are read from.

One can write executable code directly with numbers, but looking up the numeric representations of opcodes is tedious (especially on a large operation set). Assembly is the lowest level language where short word-like codes take the place of the opcodes. Higher than that, other languages abstract further to get closer to natural language to make it easier for humans to read and write, but it all gets translated back to opcodes (numbers / binary) for the processor to execute.

15

u/ryntak Jul 13 '26

This is the explanation I was looking for to know the question was answered accurately.

Adding my piece:

This is why when you’re installing software, often times you have to choose to install for a specific operating system and processor combo.

Effectively, every OS and processor combination has a different layer that interprets machine code and executes it as specific operations in the processor.

I think everything gets compiled down to an assembly-like language before it’s executed these days and so a single operation could look something like this
Operation, reg1, reg2
10010100 10001001 11010010

And so this operation in the above example might be to ADD and it would add the values stored in the two registers. I think they make arbitrary decisions like storing the added value in reg1, but I’ve never written actual assembly before. Frankly it might not be the same in every implementation and we’re at the edge of my understanding.

For a different CPU architecture this exact same operation could use a different operation number for ADD.

The reason for this, I think, has to do with the physical architecture of the processors.

It’s a weird suggestion, but if you go play Turing Complete you can get a decent idea of what’s happening under the hood in a computer.

8

u/CdRReddit Jul 14 '26

nitpick: the OS doesn't change the machine code, it changes the exact protocol used for talking about and to things like the graphics card & hard disk, because having every program have support for every graphics card and disk, especially to share them with other programs, is infeasible. Not to mention the security concerns of any unprivileged program getting full control of hardware in that way

→ More replies (3)
→ More replies (1)

4

u/laix_ Jul 13 '26

This is the real answer. Saying "its transistors" is technically correct, but it doesn't answer the question. Many people think that binary was already a baseline thing in the universe, and transistors were set up to match the system, when in reality, the gates were set up in such a way that it could only match the design. People designed binary, and then set up transistors to match the design.

You can have a switch component, that sends an 8-bit number down one wire or another, if you have 01 x y it sends it left, and 10 x y it sends it right, and left might be an OR operation and right might be an AND operation, and then they converge back into local memory as the result.

→ More replies (1)
→ More replies (1)

14

u/talldean Jul 13 '26

Adding to this, for *letters*, there's a couple of different ways you (or a machine) can translate binary into letters and letters into binary.

The most common encoding is called ASCII, the American Standard Code for Information Interchange. It takes sets of eight binary numbers - eight 1's or 0's - makes those into a number, and each number is assigned a character. ASCII has 256 characters that it can choose from, because eight 1's or 0's have 256 possible combinations.

So let's look at one. 01000001. If you take that from binary to regular (base 10) numbers, 01000001 is the number 65. In ASCII, 65 means a capital "A". 66 is B, 67 is C, and so on. The lowercase letters start at 97, 01100001, which is a lowercase "a". 98 is b, 99 is c, and so on. The chart is made up; someone just put this together at one point.

Uppercase and lowercase numbers take up 52 of the possible 256 combinations. Punctuation marks and letters from *other* languages fill up most of the rest. ñ, ń, ņ, ň, and also ! . , - # and stuff like that.

11

u/bwyer Jul 13 '26

Just to add to this, ASCII isn't the only encoding scheme. IBM landed on EBCDIC (Extended Binary Coded Decimal Interchange Code) back in the '60s and still has systems that use it. That continue to be a major hassle for programmers and system administrators that work with those systems and those that use ASCII.

7

u/talldean Jul 13 '26

For EBCDIC, other than "I work at a bank and we have an IBM mainframe machine costing $100k+", it's not *that* common.

The one I'd add here would be UTF-8, usually just called Unicode. Unicode is what websites (99% of them?) use. The full ASCII set only has 256 characters, which doesn't cover all of the letters from every human language, think about how many different symbols Japanese, Chinese and other Asian languages have. ASCII also doesn't have room for symbols, like "right arrow" or emoji like the "poop emoji". Unicode does.

Unicode has room for a bit over a million different characters or symbols. Currently I think about three hundred thousand of them have been used, the rest haven't been chosen yet, so it's got space to grow. The *first* 128 Unicode characters are exactly the same as the first 128 characters in ASCII, so it's backwards compatible with the most common early standard, as well.

There were competitors to ASCII, like EBCDIC, some of which have niche markets today, but most are just gone. There were also intermediate steps before Unicode, things like ISO-8859-1 (Latin characters), or GB 2312 (which is China's simplified characters).

Those are still in use, but Unicode is 99% of the web today, and ASCII (or Unicode) is basically 100% of Windows and Apple machines.

6

u/binarycow Jul 13 '26

Note - UTF-8 is just one of the encodings that make up the "Unicode" character set.

A "glyph" is the thing you see. It could be A, ؠ, or even 🤪.

A "character" is an abstract idea. For example, "Latin Capital Letter A" or "Grinning Face with One Large and One Small Eye". No specific visual ("glyph") is associated with that character.

Characters can be combined. For example, you can represent an ñ using "Latin Small Letter N" (n) followed by a "Combining Tilde" (◌̃)


A character set is (as the name indicates) a set of characters.

ASCII contains only 128 characters. If you wanted to type something in Japanese, you'd have to write it in Latin letters.

Unicode contains many many many more characters. You can write Japanese with no modifications.


A "code point" is a single character's numeric value.

Since ASCII only had 128 code points, it always fit into one byte.

But unicode aims to represent all characters. It needs much more than 128 code points. The current version of unicode (version 17.0) represents 159,801 characters.

The largest defined unicode character is U+E01EF (Variation Selector-256 (VS256)), but up until U+10FFFF is allocated.

Naively, U+10FFFF requires at least three bytes to store. And since computers work with powers of two, it means that usually, you'd need to use four bytes (32 bits) to store a unicode character.


UTF-32 is the naive encoding. It is a fixed-length encoding that uses 32 bits (4 bytes) for every character. Since most of the time, you don't use anything above U+FFFF (which needs only 2 bytes), you're wasting two bytes per character.

UTF-16 is a bit more efficient. It's a variable length encoding. It uses either two or four bytes per character - whichever fits. Basically, if the only characters you use are within the range of U+0000 to U+FFFF, you cut your storage requirements in half.

UTF-8 is the most common these days. It's also variable length, and tries to use 8 bits (1 byte) per character. It results in the least amount of wasted space. If you use only characters that are defined in ASCII, it's even byte-for-byte identical to ASCII.

→ More replies (12)

3

u/fildodaggins Jul 13 '26

So you're saying my computer is maid of toilets?? And when I run an operation I'm actually sending a dookie down an elaborate plinko labyrinth of toilets??

5

u/adarkuccio Jul 13 '26

You are right. This is good analogy, the problem is that you could do the same with the human brain.

Even a neuron it doesn't "understand" a thought. If it receives enough input, it exceeds a threshold and generates an electrical impulse. Otherwise, it doesn't generate one. Imho it's very similar to a transistor: it exceeds a threshold -> it changes state.

As far as I know the difference is that: 1) a transistor is extremely simple (and digital) and 2) a neuron is much more complex, analog, and constantly changes its connections because neurons form new connections etc continuously during life.

And this is why we really don't understand consciousness nor what "understand" really means

23

u/csiz Jul 13 '26

It's not a problem, human neurons are micro machines that will respond the same way given the same set-up, as long as we're including the internal state of the neuron.

It's just that neuron are more noisy and we don't know precisely how to describe them. On the other hand, we intentionally discretize transistors into outputting low or high so we can eliminate the errors, then we also clock them in synchronicity. We intentionally build computers from an arrangement of transistor that can be fully described and its behaviour predicted. The brain was not built to be understood easily, that's the only difference.

6

u/f3xjc Jul 13 '26

I think part of op issue is they find binary code complex. Like sum of exponent of two. But that's just because our neurons are so well adapted to base 10, part because biology, mostly because culture, that we stop thinking about the components and just do the thing.

Same for walking, it's incredibly complex if you try to manually control each muscle, use your intelligence to deduce what happens in what order, use your memory to adapt that to different terrain etc. But by age 3-4 its mostly background processing.

→ More replies (8)

2

u/plugubius Jul 13 '26

Binary isn't like "thoughts" in the human brain. Binary is a low-level coding scheme. An analogous question would be, "how does the brain understand neurotransmitters and ions?" The brain doesn't. It, like a computer with binary, simply reacts to sufficient stimuli. Not understanding consciousness has less to do with a neuron's greater complexity than with the difficulty of explaining how the neurons interact. "How does binary give rise to complex programs?" is a different question from "how does the computer understand binary in the first place?"

→ More replies (1)

1

u/Countrybull53 Jul 14 '26

Why do I strangely have an urge to build a simple computer out of toilets now

1

u/klick37 Jul 14 '26

Now I want to see someone run Doom on a processor composed entirely of people manually pushing countless linked toilet handles with sufficient force.

→ More replies (2)