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

Show parent comments

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.

1

u/Estorium666 May 18 '22

Hahaha damn, you got me. Yes I am that guy that was confidently incorrect. I do stand corrected though. I guess that I am so used to using GB as the binary unit, perhaps harking back to the days when GiB didn't exist, and GB was used as both.

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.