r/learnprogramming • • Apr 28 '22

If everything is ultimately binary, does't that just make programs a specific number?

I did the CS50 course a while ago and they covered binary in there. I did binary back in 2006 when I was at college too so understood the logic behind it already. It's either on or off!

When a C program compiles, it goes through it's phases and compiles to assembly and then ultimately machine code i.e binary.

Let's say our program is 5,000,000 pages of 1's and 0's. All of those 1's and 0's make up a single number....albeit a super long number.

Does that mean that the entire Linux operating system, for example, can be represented by an actual number?

If so, why are we not storing programs as a number because that would take up less space than the 5,000 pages of 1's and 0's.

110101000101011111011011111110111100 = 57000443836 in decimal. So why don't we store programs in decimal and convert that to 1's and 0's in real time?

Storage would be much less. Is that how compression works?

These may be crazy questions but it just entered my head earlier when thinking about what the binary of a program can represent.

Even shorter than decimal is HEX.... So why don't we store programs in Hex?

Any help appreciated on this one so I can wrap my head around it.

1.7k Upvotes

346 comments sorted by

View all comments

100

u/HonzaS97 Apr 28 '22

Binary is convenient for computers because of how it is all implemented on hardware level. Very simplified, electricity being present is 1, it being absent is 0. Anything else is prone to errors because of fluctuations.

There is no point in adding extra overhead by another layer converting it to decimal / hex / anything else and vice versa.

Does that mean that the entire Linux operating system, for example, can be represented by an actual number?

Yes.

And for example, an infinite sequence of random 1s and 0s will contain everything that has ever happend and will happen, every program possible, every picture and movie and so on.

23

u/Smooth_Measurement_1 Apr 28 '22

How many 1's and 0's make a movie?

I might just spend my time putting 1's and 0's on paper now and write the next Hollywood masterpiece!

62

u/HonzaS97 Apr 28 '22 edited Apr 28 '22

Well, download a movie, see how big it is and there is your answer (eg 3GB = 3 000 000 000 bytes = 24 000 000 000 bits).

Now of course, you'd have to manage them in an order that'd make it possible to decode into something sensible. Soo, good luck with 224000000000 options I guess?

10

u/jcb088 Apr 29 '22

Here's what you do:

First, look at the population growth of humans. Assuming that we a.) leave earth and populate other planets and b.) maintain an interest in this question, how many people would it take to solve this problem within the next 100 years (or maybe longer, since population growth takes time).

Also, assume that 1 in 1 million people are working on this problem. Over time, imagine an industry forms of people creating films in which the data is randomly generated 1s and 0s.

My point is: maybe some problems can only be solved by a google of people working with a google of computers. More interesting than creating a good film, what film would be born of this analysis that no human could ever intentionally think to create? Sure, 99.99999999999999999999999999999999999999999999999999%+ of the films generated would essentially be static visually and audibly, but there is an extremely tiny golden nugget in there of material that could be so inconceivably fascinating it'd all be worth it!

9

u/captainAwesomePants Apr 29 '22

There's a famous short story about this idea called "The Library of Babel." It's about a universe full of rooms. Every room is full of books. Each book is a random ordering of characters filling a 410 page book. Every possible combination is somewhere in the library. Nearly every book is nonsense, but the inhabitants realize that, if every possible combination of letters is there, somewhere in there are the true books: https://en.wikipedia.org/wiki/The_Library_of_Babel

3

u/One_for_each_of_you Apr 29 '22

"It was the best of times, it was the... blurst of times? Stupid monkeys."

12

u/Pantzzzzless Apr 29 '22

Sure, 99.99999999999999999999999999999999999999999999999999%+ of the films generated would essentially be static visually and audibly, but there is an extremely tiny golden nugget in there of material that could be so inconceivably fascinating it'd all be worth it!

This is basically the Many-Worlds Multiverse theory scaled down to movies.

-2

u/Estorium666 Apr 29 '22

Well technically 3GB = 3,221,225,472 Bytes.

I did it, I was THAT guy :D

5

u/HonzaS97 Apr 29 '22

You were what guy? The one that was confidently incorrect?

3 GB is 3 000 000 000 bytes. You are getting GB confused for GiB.

→ More replies (1)

2

u/[deleted] Apr 29 '22

This is why digital property rights get kind of bizarre: in a real sense, piracy is the illegal downloading of numbers. When you write a program, or make a digital image, or a video, or a song, or literally anything digital to which copyright attaches, you're effectively copyrighting a number.

1

u/protienbudspromax Apr 29 '22

Generate a grid of numbers say 30x30 in a 2d array. Use a random value from 0-255. Use a library to convert the raw array into a grayscale image format like png. Store those images.

Now use the above as a function and call it 300 times. Use another library to stitch those frame together in a movie format with a fps of 30.

At the end you'll have a 10 second "Movie" of random noise that started as numbers.

0

u/[deleted] Apr 29 '22

[deleted]

2

u/mikeblas Apr 29 '22

I land at "certainly not" because that sequence won't contain itself.

1

u/Svitzer Apr 29 '22

If the sequence is equal to itself, the sequence does exist within itself.

A random infinite sequence does contain any possible combination. It will contain everything. It will contain an infinite sequence of 0s. It will contain an infinite sequence of 1s. It will contain an infinite sequence of 101010101.... It will contain a perfect representation of pi, etc..

0

u/[deleted] Apr 29 '22

[deleted]

1

u/mikeblas Apr 29 '22

Binary representations of things don't exist in reality; they're concepts in and of themselves.

→ More replies (1)

1

u/protienbudspromax Apr 29 '22

The key here is "infinite". If you really actually consider infinite number of 1's and 0's then you can be sure it WILL contain everything. But you may not know if it ever ends. For many many things, this will be the case. There would be no way to write that number down.

0

u/[deleted] Apr 29 '22

[deleted]

1

u/protienbudspromax Apr 29 '22

No there is a direct correlation from continuous to discrete domain. If you do signal processing or DSP you'll come across something known as the Nyquist frequency.

This is also why a "continuous Turing machine" is mathematically not more powerful than the basic one. Hell even quantum Turing machine is not more powerful. Just faster for some specific problems.

Plus in DSP/signals they teach you how to perfectly reconstruct a completely analog signal from discrete.

The catch here is again you can do perfect reconstruction but you need to be able to use as high a frequency as needed, which Ofcourse may be infinite for some theoretical signals. So the issue at the end of the day comes to space and time. It is possible to represent everything, but we may need infinite memory or time to do it.

0

u/LilQuasar Apr 29 '22 edited Apr 29 '22

And for example, an infinite sequence of random 1s and 0s will contain everything that has ever happend and will happen, every program possible, every picture and movie and so on.

thats not true. it might contain every possible finite sequence but it might also not do it

edit: for the people downvoting, you might want to check this out

2

u/rosaUpodne Apr 29 '22

It depends on how you define random. Key words here are infinite and random. Actually, while it is technically true, it is probably impossible to prove that infinite sequence is random when it is.

2

u/Optimal-Barnacle2771 Apr 29 '22

Its impossible to prove that any given infinite number is random for example, pi. But, could we conjecture that there is an infinite random number and build off of that? I mean it is certainly possible to have an infinite random number, just impossible to prove that a specific one is.