Forum > Other

Why do we use binary logic in programming languages?

(1/5) > >>

Peter H:
Because a Boolean is a byte, we could instead use quad Logic this has four values:

true,false,undetermined, dont care.

This is fully compatible to binary logic, but practically problems can be expressed much more compact and clear.

Martin_fr:
Feel free to create an enum, and overload operators as needed and possible....

Also "Boolean is a byte" is mislead, if not wrong. Boolean can be stored in a byte. But when bitpacked (array/record) it can be stored in a single bit.
There is also the possibility to store it in a word, longword, or quadword.

Boolean is a concept. Storage is something added by implementation.

As for other concepts, there are languages that bring in undefined and/or null. And not just for booleans, but for other types too.



avra:

--- Quote from: Peter H on April 08, 2021, 05:08:06 am ---This is fully compatible to binary logic, but practically problems can be expressed much more compact and clear.
--- End quote ---
Search the net for fuzzy logic. It's fun, very powerful and has wide appliance potential. You'll like it, I promise.  ;)

MarkMLl:

--- Quote from: avra on April 08, 2021, 09:40:27 am ---Search the net for fuzzy logic. It's fun, very powerful and has wide appliance potential. You'll like it, I promise.  ;)

--- End quote ---

I suppose that an answer to the "why" question is that we were building electrical switching circuits using relays a long time before we had electronics which could generate and compare voltage levels accurately.

There were obviously mechanical analysers/integrators of various types, but they were used to solve numerical calculations rather than for control purposes. I suppose that at a pinch we could call cam-based control systems non-binary, but by and large they didn't have a precise computerised equivalent.

/Technically/, Babbage could have built a relay-based computer in about 1850. In practice, it would not have been possible to get it to operate fast enough.

MarkMLl

Bart:
The classic True, False, FileNotFound.

I have a Boolean factory which has support for True, False, Maybe (it compensates for the uncertainty principle in quantum mechanics).
I can give you the url if you need it.

Bart

Navigation

[0] Message Index

[#] Next page

Go to full version