r/computerscience • u/VEXLuminox • 4h ago
Discussion Why do we use binary for coding?
why not use something like quaternary or tertiary for computers?
I mean biology uses quaternary for dna sequencing, why not computer source code?
0
Upvotes
61
u/apnorton Devops Engineer | Post-quantum crypto grad student 4h ago
Binary translates nicely to hardware (hi vs lo voltage is easy to detect and maps nicely to switches for logic gates; three (or more) state circuits are harder to build.
From a computation theory perspective, changing bases doesn't really unlock any significant computational power, either.
15
u/devdruxorey Computer Scientist 3h ago
It is easier to distinguish between two voltages (on, off) than between different voltage levels that can fluctuate.
6
u/rupertavery64 2h ago edited 2h ago
In binary, a single bit is represented by voltage on a line.
0V is 0 and non-zero voltage (3.3V, 5V) is 1. The upper voltage depends on the transistor types being used, among other considerations. Smaller circuits generally use lower voltage, because they are closer together, and should generate less heat.
Having only 2 voltage states makes building circuits really easy - it can be either on or off.
Having more than 2 states means you need to add additional circuitry to check if the voltages are at the correct level - at every input. And the voltages aren't perfect, they can be 2.8-3.5V for 3.3 levels (as an example, it's not the actual specs for a 3.3V transistor).
So you need to space out the voltage levels so that they don't get confused with one another, or make really accurate voltage level detectors.
If you space them out, you need to have higher voltage ranges. If you make them more accurate, you need to make more complex circuits. More complex circuits means more power draw. More power draw = hotter and less efficient. High voltage ranges also means more heat.
All that just to encode 1 or 2 extra bits in a single line, and it becomes less and less economical and practical as you scale up.
One thing though is that in SSDs (solid state drives), we actually do use multi-level voltages to pack more bits in a single cell. This is fine as the cells don't do much else but store electrons. Current technologies allow us to store up to 5 bits per cell, using 32 voltage levels.
https://en.wikipedia.org/wiki/Multi-level_cell
We don't use this in processors because of the complexity and the speeds we need to run the transistors to perform logic operations.
5
u/program_kid 4h ago
Here is a post from a few years ago that has some good answers. https://www.reddit.com/r/computerscience/s/MdxfkKMEdy
5
u/Upbeat_Assist2680 4h ago
I mostly use ascii, but sometimes I switch on the Unicode support and then the whole universe goes plaid
1
u/tcpukl 3h ago
Originally voltage reasons. But it's great for booleans.
1
u/FredSchwartz 3h ago
https://www.scientificamerican.com/article/this-number-system-beats-binary-but-most-computers-cant-use-it/
1
u/pamalapamela 2h ago
Binary is simpler for computers.
1
u/Several_Version4298 2h ago edited 2h ago
We use binary because memory has two states on or off.
Though when actually coding you use hexadecimal and decimal for convenience.
1
u/gomorycut 2h ago
And, yes, when storing data with DNA strands, people encode data with 4 symbols instead of 2
1
u/FernandoMM1220 2h ago
mostly because our circuit designs make it easy.
1
u/forty_thousand_bees 1h ago
Along with the answers others have given about playing nice with hardware, for computer data itself, it actually wouldn't be wrong for the most part to think of computer data as built out of 256-ary units, since that's what a byte is, and the byte is by and large just about the smallest unit of information you'll see when working with computers (all memory is byte-addressable, and the only CPU instructions that operate on any unit smaller than that are bitwise, which are a bit of a special case).
1
u/BranchLatter4294 44m ago
What material would you suggest for quaternary processing?
1
u/Technical_Ideal_5439 8m ago
Because on/off is easy to implement in hardware. Though tertiary has made some noise lately. And Quantum I assume is going to happen,
0
u/ivancea 3h ago
It's the smallest number (not counting unary, which is weird and technically its "bits" are stateless). And everything over it (ternary, quat, dec...) can be represented by it.
Also, many reasons, like simplicity reading electrical signals and other I don't know.
Btw, don't compare this with biology. Computers work with logic, biology works by pure chance basically, and there's no reasoning to it. It works because it happened to work and evolution and reasons. But it doesn't mean it's optimal. It is, in fact, a very, very bad system. Everything in biology is badly optimized.
But answering your question: yes we could. We just don't. For the aforementioned reasons
0
u/gomorycut 2h ago
Same reason vinyl records use grooves and troughs.