r/computerscience • • 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

23 comments sorted by

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.

3

u/VEXLuminox 3h ago

interesting, thanks for the info! in this sense would it not be better for SSD data storage to use tertiary?

11

u/synexo 3h ago

They kind of do (not ternary though), as they store multiple bits in single voltage states, but powers of 2, so 2 bits in MLC and 4 bits in QLC as 4 and 16 voltages respectively.

5

u/Gerard_Mansoif67 3h ago

and 3 bit in TLC, and iirc they try to do 5 bit with PLC.

2

u/Doug2825 1h ago

SSDs do use multiple voltage levels. This works because the flash cells that store data (where most of the cost is) just store whatever voltage they are given. So it is worth it to make a complex control circuits to write/read multiple voltages.

2

u/Successful-Cash5047 1h ago

No, unfortunately ternary wouldn’t be better. 

Transistors are either on (1) or off (0), and they do this by either passing current ((1), “valve open”), or not passing current ((0), “valve closed”). 

To represent 3 states, you’d need to use 2 transistors. But if you use 2 transistors you could’ve just represented 4 states by using binary. 

We do have standard data sizes (8 bits to a byte), and that is mostly equivalent to using more states. 

1 bit only has 2 states but a nibble (4 bits) has 16 “states” (form 0000-1111). So it’s effectively like using a “hexadecimal bit”. 

1

u/tommyblastfire 10m ago

To add to this, the question might become “well, why don’t we have transistors that can represent more than 2 states?” And the answer is that we do, but they’re bigger than 2-state transistors because they’re more complicated, and we also don’t use them because they introduce more chances for error in determining the signal. You could theoretically invent a transistor that has a different state for every integer voltage, 1,2,3,4,5,6,7v etc. But there’s less certainty in deciding between the voltages, which can already be a problem with binary transistors deciding between what counts as on and off.

1

u/Ma4r 1h ago

They do, though rather than tertiary, thry rypically store up to 4 bits per cell, so it's (2,4,8,16)-ary depending on your specific model

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/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.