r/learnprogramming • u/Smooth_Measurement_1 • 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.
2
u/ruat_caelum Apr 29 '22
This is like saying which is heavier 10,000 pounds of feathers or 10,000 pounds on concreate.
They are both the same weight.
Likewise the "number" and the "program" have the same amount of information you can't "Shrink it" by converting from one to the other because they are the same.
A rocket transporting our feathers or concrete to space would need the same fuel because the weight is the same. A memory card holding the number or program would need the same storage because the information is the same.
We don't have the means to do that. We have the means to hold an electrical charge (1) or not charge (0) how would we have a "base ten" with that? either something has charge or not. two states, so binary.
And again even if we did have a base ten circuit the DATA is the same. Just like the wight of feathers or concrete is the same no matter if we convert one to the other the fundamental measurement is the same.
It is not as you aren't "compressing" anything you are "Converting"
Well let's think about this logically. What makes it "shorter" the "bandwidth" of the symbols right? So if we have base 8 OCT we only have symbols 0-7 (8 different symbols) base 10 had 10 of course, base 16 HEX has 16 symbols by extending into the letters A-F, what we made up a base 36, it runs from zero to nine, then A, B, C, like Hex but all the way to Z. We could hold 36 values in a single position, and the value of 37 would be represented at "10"
Now let's extend this logically even further. Say we just draw random symbols without duplication until we have 300,000 of them. Now we can hold a unique value in 1 symbol from 0-299,999 (base ten)
Does this gain us anything? Are we making the NUMBER smaller, or just how it is represented? isn't this just another type of CONVERSION like conversion feathers to concrete but still having the same weight?
The answer is yes, it's a conversion, not compression. Even though you are displaying the "number" in fewer and few digits, the VALUE of the number will always be the same.
How does compression work then?
The easiest answer is that it throws away data you can't use. The VLUE of the number is less or fewer, the weight of the feathers is less, etc. For an MP3 a computer program looks at all the data and determines for instance that because a big bass beat is playing at the 3 second mark, your human ears cannot hear the flute or tringle anyway. So instead of keeping that data that you won't be able to use. It removes it completely. This is LOSSY compression. LOSELESS compression is a bit more difficult to explain and I'll skip that for now