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.
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?
→ More replies (3)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
→ More replies (1)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.
→ More replies (1)2
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.
→ More replies (8)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
→ More replies (2)
59
u/Bacon_Techie Apr 28 '22
The reason we store things in binary in the first place is because it is the most accessible format for computers to read, unless it’s an analogue computer. In order to store that decimal number in the first place it would just be converted to a binary number. They both take the same amount of space because they contain the same amount of information. It would take the same amount of information to store 23 as it does 10111.
106
u/Immanonner Apr 29 '22
Hold on....I think I understand...
hits blunt
If everything is ultimately binary...
Coughs
Does that mean our life can be represented by a specific number?
And if we knew the whole number sequence beginning to end we could potentially examine the end of the sequence to tell the future before it happened?
Isnt that basically DNA?
Some say that Calculus is the language god speaks...but now I'm beginning to wonder if he only speaks in binary.
Great questions, loved reading the answers--this is why I follow this subreddit.
36
u/xxxxx420xxxxx Apr 29 '22
We can represent everything as numbers, but shit changes all the time and we can't know what's going to happen in the future at certain scales <hits vape>
5
u/caboosetp Apr 29 '22
we can't know what's going to happen in the future at certain scales
If you call dispatch, they can probably give you a rough idea of which trucks are headed to those scales now though.
2
u/Tino_The_DM Apr 29 '22
And while we can represent anything as numbers, we interpret it all as language, and language is just arbitrary. There is no sign without a signified, and what is signified is arbitrarily determined <sucks last little bit out of the roach>
29
14
u/Cquintessential Apr 29 '22
No, DNA has context. Codons are 3 nucleotides, which translate to various proteins. While you could abstract the literal DNA sequence to a number, it would have very little meaning without the part that reads it.
A better statement would be that everything is binary in state. It’s either there or it isn’t. Now you can extrapolate and say that you can have “nothing” or “everything”. “Something” is every value in between that nothing and something.
So between 0 and 1, there are infinite rational and irrational integers in the interval. If you look at mathematics and topology, you can see that manifolds can have their “something” and “nothing” translated across dimensions (holes and such.)
Anyway, I’m neither a mathematician or a theoretical physicist, so this is probably all wrong and terribly communicated.
7
u/BeauteousMaximus Apr 29 '22
I am a Strange Loop by Douglas Hofstaeder goes into this and a lot of related questions.
3
u/captainAwesomePants Apr 29 '22
I'm super excited you cited this one. Everybody talks about Godel, Escher, Bach, but Strange Loop is great!
2
2
2
1
u/protienbudspromax Apr 29 '22
There are a subset of numbers that cannot be represented in a turing machine tho. Any set which is uncountable are thus by nature not something that can be resolved inside a turing machine.
Things which are discrete and enumerable are things that turing machines can compute or atleast understand.
Countable things are anything where you can say a "next".
Like the natural numbers. You can say that 2 is 100% coming "next" to 1 and there is nothing in between.
But if I ask you what comes after 0.01??
You cannot give me a number, because any number you give I can give back a number between your number and this 0.01 so my number should have been next?
These kind of sets is where turing machine cannot compute.
1
32
31
u/Sticky-IPadKid Apr 29 '22
i literally thought about posting something like this yesterday.
my entire hard drive just stores a number.
the cure to cancer is a number.
if you can find a way to store it, your consciousness is just a number.
if you can have a file format that stores atoms, the entire universe is just a number.
7
u/top_of_the_scrote Apr 29 '22
makes me wonder if you can brute force new ideas by randomly flipping bits
like you generate a PNG with random pixels and you squint at it like "yeah that looks like a 9 cylinder engine" lol
6
u/umhiwthishappeninh Apr 29 '22
project idea: randomly generate images with random pixels until a new idea is created
→ More replies (1)2
u/top_of_the_scrote Apr 29 '22
yeah was thinking you just bombard your brain until you solve the 3 body problem or succumb to the radiation /s
2
0
31
u/obp5599 Apr 28 '22
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?
No because what you read as 1 and 0 is not the computers representation. When you read '5' on a computer screen, that is an ASCII value, represented by 1 (8 bits) in memory. To the computer EVERYTHING is binary. Its not a matter of choice. It has to be, based on how the hardware works. So the number 570 would be 24 bits, while 570 in binary would be 10 bits
29
Apr 29 '22
Basically you have independently discovered that turing machines are countable! Let's parse that theorem down:
Turing machines are the formal model of computation.
Turing machines have a finite representation on a linear tape using a finite alphabet.
Because their length is finite, and the alphabet is finite, we can order them in lexicographic (or dictionary) order.
If something can be ordered, it can be numbered.
As an extension: The set of all mathematical problems is uncountably infinite, whereas the set of all computer programs are countably infinite. That proves that some problems cannot be solved by a computer.
This is undergrad theory of computations stuff. Good job figuring the essence out on your own.
11
10
u/Long_Investment7667 Apr 29 '22
If you want your mind to explode, search for Gödel encoding . It starts with the idea that every program in a specific language can be represented as a number and every interpreter of that language that evaluates a program is “just” doing arithmetic
8
u/48911150 Apr 28 '22 edited Apr 29 '22
How do you suggest we store 57000443836 in order to save storage space?
4
5
u/arbobendik Apr 28 '22
Your computer can only store and calculate with binary values so any other system is not an option
5
9
Apr 28 '22
It doesn't quite work like that.
Computers are state machines - they move from one state to another. The ultimate simplicity in state management is a system that has two states - on and off. This on and off situation can be represented by 0s and 1s, and it can also be usefully represented by electrical voltages. That's all a computer is.
What you're talking about is actually the state machine viewed in reverse. You can take these states - on and off - and use them to represent numbers by configuring them in specific ways. It's more the flow of 0s and 1s that's important though.
It's like, 1 here changes the 7th item there into a 1. If the 7th item is a 1, the 12th item becomes a 0. If the 12 item is a 0, the 15th item becomes a 1 etc. What's the value of the 15th item if this first is a 0?
That's sort of the value of computers - they build in these state transitions, but allow for changes to the way the transitions happen. It's actually the variance in transition that's useful.
3
u/Putnam3145 Apr 29 '22
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?
You're storing the same amount of information, just in about 30.1% the symbols, which doesn't matter that much.
Despite all the people saying that we don't do this... we kinda do? A quad-level cell solid state drive holds 4 bits in each of its units, which is the same as a single hexadigit. This does save on space, but it's less reliable, which is why we we're on binary in the first place.
3
u/yiliu Apr 29 '22
As others have pointed out: yep, a program is just a number.
This reminded me of an old thought experiment, from the early days of file sharing. All files, and in particular all media files, are also just numbers. A video of the latest Marvel movie is just a number.
So you could take that number and perform some math on it: divide it by some other number (call it a), and get the result, b. Take that number and use it to divide a file containing a fresh rip of the latest, I dunno, Kanye West album, getting c.
You're left with a bunch of numbers, meaningless on their own. But a * b equals the latest Marvel film. b * c equals the most recent Kanye album. And so on.
Are the numbers therefore illegal? The numbers don't mean anything on their own. No number can be said to be 'part' of a specific piece of media, any more than it can be part of any other. Is it the formula (i.e. a * b) that's illegal? Or just the calculation of that formula?
Anyway...interesting to think about.
3
u/martinborgen Apr 29 '22 edited Apr 29 '22
Apart from compression, yes to all.
It goes even further though! The binary number is itself actually just a representation of an on/off configuration in a bunch of wires that causes switches to be on or off in a certain way, that makes a certain operation happen inside a computer.
Or as someone once said: digital electronics is actually just lots of very small and fast analogue electronics.
This is why it's stored as binary, because it's not the value of, say, fourteen (decimal 14, binary 1110) that's what we're after, but that these four wires are ON, ON, ON, OFF that causes the next clock cycle in our CPU to do what we want.
2
2
2
u/mushpotatoes Apr 29 '22
For what it's worth. Any program is just a number, but different processors will interpret that number in different ways.
Any thing that can be measured can be represented as a number, but the context of the number is also important. In the case of computers, that context would be the machine language/instruction set.
2
u/ruat_caelum Apr 29 '22
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.
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.
So why don't we store programs in decimal and convert that to 1's and 0's in real time?
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.
Is that how compression works?
It is not as you aren't "compressing" anything you are "Converting"
Even shorter than decimal is HEX.... So why don't we store programs in Hex?
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
2
u/Rythoka Apr 29 '22
Congratulations on re-discovering the reasoning behind Gödel's Incompleteness Theorem! It's math-heavy, but there's some good content out there if you want to learn more about it. I recommend the YouTube video by Veritasium: https://www.youtube.com/watch?v=HeQX2HjkcNo
From a programming perspective, the arguments in that video about the existence of true statements without proofs is about undecidability, a concept which defines the limits about what can and cannot be solved by a computer.
1
u/crossedline0x01 Apr 29 '22
Dude! I just posted a comment about the re emergence of analog computers hahaha. It's by Vertasium too, they have really good stuff.
2
2
u/vi_sucks Apr 29 '22
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.
Because the ultimate data storage is a bit. Which stands for "binary digit". At the basis of everything what you have is basically an electronic switch that is either on or off.
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?
We do. Well not in decimal but more likely in hex or whatever. It's just easier to store numbers in powers of 2 because, again, the final base level storage is in bits.
2
2
Apr 29 '22
Oh, it's worse, any movie or song you download is also just a number. That means that copyright is literally making certain numbers illegal to use or look at.
1
1
1
Apr 29 '22
Lots of great answers so I'll just comment on one point others have missed.
Storage would be much less. Is that how compression works?
Not compression, but that's how multi-level cell flash memory works. The original technology is binary, but if you use four charge levels you get two bits per cell. 5 bits as the current limit of practical technology, which requires 32 distinct levels.
The cells stay the same size, so you can increase the storage density by a factor of four or five.
But the disadvantage is that it's harder to precisely set or read the charges. So MLC memory doesn't last as long as single-level and it's typically slower, especially the write speed.
So the memory manufacturers are another step ahead and actually use SLC to buffer newly written data. This is one of the reasons why burst write speed is better than sustained.
1
u/Prize_Bass_5061 Apr 29 '22
Tangentially, your questions are also related to hashing.
Every file on a computer is a very large, specific number. We can generate a shorter number (hash) that represents the larger number. That’s what the md5sum terminal command does. It’s how we compare files instead of comparing them byte for byte.
In general that’s what hashing is. Generating a smaller number to represent a larger one. Hashing is not compression because data is lost. So we cannot compute the large number given its hash.
1
u/Graphenist Apr 29 '22
Yes, but its an extremely long and precise number, and you wont save space converting it to Base-10. Informational entropy will forbid you from compressing arbitrary data an arbitrary amount...
At least, all math and logic seems to indicate that arbitrary data can not be compressed arbitrarily. If you could break that assumption, it would easily be the greatest discovery of all time. But dont get your hopes up because its pretty obviously impossible, and can be proven to be impossible
1
u/nomoreplsthx Apr 29 '22
Every program is a number Now go read about Godel's incompleteness theorem and be prepared to have your mind blown: it also turns out every possible sentence in any language can be represented by a number, and you can prove insane things about any possible system of logic from that fact.
1
u/Autarch_Kade Apr 29 '22
Related to your questions is this video I watched just an hour ago:
That unbelievable function that can compute EVERYTHING! It discusses boolean logic and how a few simple operators can be used with any input to make every single possible program.
1
Apr 29 '22
Representing a single state of an operating system/app is one thing but both are constantly changing states over time with input so it’s never just a single number forever.
The other reason has to do with how data is stored on solid state drives. They are stored in charge flash trap devices which I believe can only exist in 8 states at the moment.
000 001 010 100 011 110 101 100
You have to change the way things are stored as well as how they are compiled too accomplish
1
u/arkie87 Apr 29 '22
I mean, if a program is 1 kilobyte, that is 2^(8*1024) which is a number with 2467 digits, which would take of up nearly a kilobyte of memory, so I'm not sure you would really save that much space
1
u/arkie87 Apr 29 '22
perhaps 30 years ago, this would have been a convenient way to compress programs, but now adays, space is not really an issue. the time it would take to decompress wouldnt pay compared to the space saving.
1
Apr 29 '22
Yes, Google the illegal prime, which is actually a program that breaks encryption but in number form
1
u/MurderousTurd Apr 29 '22
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?
We know that computers "think" in binary. So when memory is stored, it is in binary.
Even though the decimal(or hexadecimal) representation of a number looks smaller, it still gets stored on the memory as binary, and then gets converted to decimal or hexadecimal for readability purposes.
It is possible in theory to have a memory based on 10_decimal position switches, but the information would have to be converted to binary for the computer to use, a process that would take time to do. In fact, there is a device that can kind of do this already - an analog to digital converter, but they tend to use very specific readings and and in small (comparatively) quantities.
For information to be stored an used in other formats would require computers built on that format. How that would work is well outside my wheelhouse and would be better for a computer scientist/engineer to explain.
1
1
1
1
u/WildkurtOfGood Apr 29 '22
At the hardware level you would be limited by the number of bits the computer can process at once. So you would still be restricted to lines of code. It would be possible to line up everything in 1s and 0s, but that number would larger and beyond comprehension. Keeping in mind that every position represents 2 to the power of some exponent, it can get way out of hand exponentially.
1
u/BeauteousMaximus Apr 29 '22
We do store programs in binary, because everything stored on a computer is stored in binary. Both the source code and the compiled executable program are stored in binary.
The reason we write with programming languages instead of just going in to poke at zeroes and ones is that programming languages provide useful abstractions that allow us to not worry about lower-level issues like which memory registers hold the relevant bits for some value, and instead we can have things like classes and objects and functions and database connections and web requests and file input/output and a million other things where you don’t want to worry about how they are implemented on a specific machine, you want to make them work consistently and handle common errors and complications without thinking about them.
Of course…below the level at which all data is binary, all signal is analog :) for example:
https://en.m.wikipedia.org/wiki/Single-ended_signaling
The widely used RS-232 system is an example of single-ended signaling, which uses ±12 V to represent a signal, and anything less than ±3 V to represent the lack of a signal.
1
u/madhousechild Apr 29 '22
Imagine writing a program that works out to 6.057991032254544522218884 x1046 and the bug is that it must be 6.057991032254544522218883 x1046. Wow.
IDK but I like how OP thinks. I once wrote a program to reduce yelp data to a bitstring and then each business had a number, but they weren't unique.
1
1
u/green_meklar Apr 29 '22
If everything is ultimately binary, does't that just make programs a specific number?
Yes. This is more of a theoretical CS question than a programming question, though.
Also, if everything is ultimately binary, that raises the question of how you tell where a given number ends and the next one starts. You could interpret the contents of your hard drive as different programs depending on where you decide to stop.
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.
Because the storage is binary, too.
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?
Because the decimal storage would be more expensive per digit. Indeed it would be about as much more expensive as the number would be shorter (and would be less convenient for programmers). You can't get information 'for free' converting either way.
Is that how compression works?
Not really. Data compression just converts binary to binary, the trick is that you use it on binary numbers that have nonrandom patterns in them and you take advantage of those patterns to map larger numbers onto smaller numbers.
1
u/humaneWaste Apr 29 '22
Because to store any number requires the binary representation for digital storage.
Everything is stored as bytes(a collection of 8 bits), which is also base 256. Hex is only base 16. Storing a program as hex (one hex character per byte) would actually double the size of it.
Storing decimals as bytes could triple the size:
32 bits is 4 bytes, or four characters. Which can represent a value upto 4.3 billion, which is 10 characters(decimals).
Ultimately bits are only sub-addressable. Bytes are the minimally addressable limit, which is what memory and storage both utilize as far as software developers are concerned. The hardware deals with bits transparently, for the most part.
Like, if you open a file to read or write you'll be using bytes. Same with allocating and addressing memory. If you want to deal with bits there's bit-wise operators....
So that's where we're at. Storage (and memory) is essentially base 256, far better than hex or decimal! But regardless, computers compute and store everything at the bit level.
1
u/krackout21 Apr 29 '22
It may sound mind blowing these days, but in the past there were programmers who wrote binary directly. Not assembly, binary! More usual, for convenience, they wrote in hex and converted to binary.
The most known example of such a programmer is Steve Wozniak. If I recall well he wrote the firmware and BASIC of Apple I in binary, because he couldn't afford assemblers and compilers - or time sharing computers; all of them expensive in the past.
1
u/andrisb1 Apr 29 '22
Somewhat related, that's actually how RSA encryption works. Take a file in the form of a number, do math on it (really just multiplication), result is the encrypted file. To decrypt it you would need to do the math in reverse, but without knowing other part of the equation (the private key) you would need to brute force it. Which, due to size of the numbers is nearly impossible.
2
Apr 29 '22
Just an addendum to this, it's super cool how RSA uses prime numbers. It multiples two large primes together, making an even larger semiprime. That semiprime has the two original primes as its factors, but the math required to find all the factors for the semiprime is very time consuming. That's why it's still possible to securely encrypt things with this system using large enough keys, but cryptographers also know that certain quantum algorithms are going to be able to do the factorization much quicker and so RSA encryption will be rendered useless once quantum computers become more of a reality. That's because--going back to binary--quantum computing isn't limited to just 0 or 1, off or on, but can be off and on at the same time. Which is a concept I personally still cannot get wrap my head around, but it all wraps back around to quantum physics and Schroedinger's cat.
1
1
u/diorcula Apr 29 '22
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.
I don't think this is true, as this would only account for 1 of the states of the program?
When you press a button or give some input there will be a change in bits somewhere in the program ultimately changing the outcome of the number
Therefore I think it would probably be a range of numbers?
1
u/Grtz78 Apr 29 '22
A program is a state that in its state encodes the means to alter its state.
That's all a Turing Machine really is.
1
u/sullyj3 Apr 29 '22
To add on to the other excellent answers, there's a very approachable book called The Information by James Gleick that goes into this stuff and the implications in detail.
1
u/igglepigglesblanky Apr 29 '22
If you think it is possible to have a sentient computer (AI) then some very large numbers are sentient .
1
Apr 29 '22
And if numbers are just patterns? Isn’t programmes just a pattern? It’s everything one pattern!
1
Apr 29 '22
aaah i love this question !!!
here's short python program that will show you the actual 0s and 1s that represent any file or program on your computer:
import sys
# Read the file and load it into a string
filepath = sys.argv[1]
f = open(filepath, 'r')
st = f.read()
# Convert the string to binary
bin_data = ' '.join(format(ord(x), 'b') for x in st)
# Display the string
print bin_data if you save this program into a file called hex.py, you can run it like this:
python hex.py /link/to/file/you/want/to/see/in/binary/codesource: https://www.quora.com/How-do-I-get-the-binary-code-of-any-file
one thing that confuses me about this though is that these are separated by spaces and not all of these blocks are the same length. i guess it would be more accurate to prepend an appropriate amount of 0s to those blocks which are less than 8 bit (=1 byte) long?
1
u/chervilious Apr 29 '22
Does that mean that the entire Linux operating system, for example, can be represented by an actual number?
Yes, Ted ed make a good video about it
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.
Because binary is easier to work with for computers, physically it's just whether something has a current or not, if you could make something that has 10 states and is efficient enough you can make a new computer architecture. Current computer architecture relies on binary.
From StackExchange:
Because binary lends itself naturally to an ON-OFF system where ON means a current and OFF means no current. Using 10 different voltage levels would be very error-prone.
... Overall, the binary system wins because it is the easiest to design circuits with and the easiest to analyze and implement.
Other than that, remember that everything is recorded in binary, even decimal. There will be no space-saving whatsoever, in fact, it will make the program slower because you need to convert it.
110101000101011111011011111110111100 = 57000443836 in decimal. So why don't we store programs in decimal and convert that to 1's and 0s in real-time?
We human look at this and said the right one is shorter, computer store both as the same.
Even shorter than decimal is HEX... So why don't we store programs in Hex?
As stated before, both are the same length for computers. Unrelatedly when you're reverse engineering you're usually looking at the hex instead of the binary, it's easier for humans to reverse engineer a hex compared to a binary.
1
u/donotlearntocode Apr 29 '22
I see a lot of comments in here about why we store data as binary instead of decimal, but not about how "programs are numbers". That took me some time to wrap my head around.
So when you write a program, it gets compiled from the language you wrote, which is what converts it to "a number", but it can also be seen as a list of numbers. These numbers represent instructions to the CPU. Instructions might be add this, load that, jump there, store this, etc. Each instruction maps to a number. So add might be 1, jump might be 2, etc. So when you turn the computer on/load a program/boot the OS/etc, you tell the CPU to start reading numbers from the big number that is your program. Computers' instructions are a specific bit-length, so it reads that many bits out of your program. That number lights up a series of bits on the cpu, which causes the CPU to do whatever instruction is associated with that instructions, then the next chunk of N bytes are read.
2
u/tidewater41009 Apr 29 '22
Any ordered sequence of numbers can be represented by a single number. Two way Video number function.
1
u/AlexAegis Apr 29 '22
"Can a program be represented as a number"
yes
"can linux be represented as a number?"
No*.
* But it can be represented as a set of numbers because you can compile linux in many ways and they would all produce a different result.
But it also depends on what we mean when we say linux. Is it the combination of all possible things you can build from it? or the sourcecode itself?
1
u/cuddleslapine Apr 29 '22
by linux, I think he meant a Linux installation at a given time (or rather, I guess the OS as whole, that runs on a machine)
1
1
u/hali_mehdi Apr 29 '22 edited Apr 29 '22
I tkink, and i might be wrong, that there is actually no such thing as decimal either, in machine world decimal it self is but a graphical representation of a binary number that actually stored in memory, that is why we can not sace space by converting a binary to decimal, cuz actually in memory it does not get converted.
1
u/wgunther Apr 29 '22
This is a very good observation, and a very important one in mathematical logic: https://en.wikipedia.org/wiki/G%C3%B6del_numbering
1
1
u/pocketmypocket Apr 29 '22
The only other thing to mention here, your compiler makes the number specific for your hardware and/or operating system.
I couldn't take an arduino program and put it on my CPU.
1
u/DryPenguin0w0 Apr 29 '22
bro if you wanna engineer a wacky base 3 computer prototype and write assembly for it, i'm all for it
1
1
u/the-B-in-Brick Apr 29 '22
It is true that everything in a modern system is binary, until quantum computing becomes reality.
That’s because data is stored one bit at a time in a transistor, and that transistor has two (bi) states loosely viewed as on v off. (Hence BInary-Transistor = bit).
Current systems cannot store in decimal, because transistors don’t have 10 possible states, only two. We write it on paper as decimal because that’s a convenience for humans. Current computing architecture doesn’t understand decimal. Or even alpha-numeric. Only binary.
The different coding languages are all created for human convenience. The C language, considered one of the closest languages to that understood by a binary computing system, isn’t read by a computer.
When completed by the human it gets compiled. It is converted to a series of binary “pieces” in a way that’s specified by the Instruction Set Architecture (ISA) of which you may have heard of x86 commonly used by Intel & AMD, or RISC used by ARM.
From here, it’s fed into the processor comprising two main parts — the code & the data.
For example, “add the data stored at location (register) A to the data stored at location B, and save the output to location C.” It is thus the compiler’s job to convert human-written code into machine readable code (fun fact: different compilers churn out slightly different results, and some coders are very loyal to their chosen compiler)
The exact “rules” for this process is specified by the ISA. (The above is a simplification). Because of the differences in architectures, code compiled (into binary) for x86 can’t be run on RISC. But the human written code (aka source code) hasn’t yet been broken down into machine code, so it can (generally) be swapped between systems.
This means that your broader question is right, all code and data is binary, and that in theory could be represented as a decimal number.
The entire movie The Matrix could be represented as one really really long decimal number.
But if you were to change just one single frame of it, that long decimal number would look entirely different. In binary (or decimal), a screenshot of a pic would be a number entirely different from the original.
If we simplify the concept and instead of a movie represented as an absolutely unique number we took, I dunno, a pixelated cartoon of an ape what might you get? Yup. An NFT. But that’s a story for another time.
1
u/lordtnt Apr 29 '22
Yes and copyrighted music, videos, and everything digital is like copyright a number.
https://en.wikipedia.org/wiki/Illegal_number
Numberphile has a 9 year old video about this: https://www.youtube.com/watch?v=wo19Y4tw0l8
1
u/HandMadePaperForLess Apr 29 '22
You are correct, and it is an interesting idea. The reasons we don't translate the number are:
It takes a ton of work to translate between systems. Going binary to hex is a little easier than to decimal, but it is a lot of work.
We don't have a good way to store decimal or hex that a computer can read. Computers read binary, and we can store that in a way that goes straight into computer brain. For this we would need to store the number somewhere else and translate it in binary signals.
1
u/jacobyllamar Apr 29 '22
The most basic computer component is the switch. And, of course, it's innately binary (on/off.) So that's why we store things in binary. If you had a transistor switch that has 10 different emission levels, then you could store one decimal numeral there, but building that is WAY more complicated than a binary one, so we just build tons of 2 level switches.
I've skipped many details, but, more or less, that's why we can't just compress something to decimal.
1
1
u/some_clickhead Apr 29 '22
If you store programs in decimal, there will still need to be a bunch of 0's and 1's to represent those decimals, because as you said, 0's and 1's is all that the computer can store at the end.
It's similar in principle to compression, yes, it's just that in this case you aren't compressing anything because you haven't reduced the amount of information necessary to represent your code (the decimal would have to be long enough to uniquely identify your program, so it would take up a lot of space regardless).
An easy way to understand how compression works is this:
[0, 0, 0, 1, 1, 1]
could also be represented by:
[ (0, 3), (1, 3) ]
If I decide that in the second array, for each pair of numbers (x, y), x represents the value, and y represents the number of consecutive instance of that value. This type of representation would achieve a very high compression rate for arrays which feature a lot of consecutive, similar numbers.
Then I could call the first array a PNG and the second one a JPG, and I would just need to make sure that other computers know how to read and interpret them according to their specifications.
1
u/dota2nub Apr 29 '22
What do you save that number in? Oh yes, binary! Whoopsies!
You don't actually, have access to anyting else at the memory level.
1
1
u/crossedline0x01 Apr 29 '22 edited Apr 29 '22
Some really smart people are trying to make analog computers a thing again. I guess its inevitable once we reach the climax of Moore's law , which I think is closer than most think. We already have a transistor that's pretty much the size of an atom. Once we breach that barrier I think the number will be more of a continuous unknowable number rather than a discrete absolute one. The best well be able to do is approximate its value.
I'm not sure, but I think right now an approximated program is an impossibility. A problem that could only be solved with an analog device itself. Cool and interesting question.
1
u/Greedy-Turnover5659 Apr 29 '22
Dayummm ...🤯🤯 Literally blew my mind after reading your first question ... Never occurred to me 😂😂
discord : Blockchain Learning Community DApp World https://discord.gg/jUQwyKQt2V
1
u/ImprovisedGoat Apr 29 '22
This is all absolutely mind blowing. Is there a book I can read more about this?
1
u/Pickled_Wizard Apr 29 '22
Does that mean that the entire Linux operating system, for example, can be represented by an actual number?
Yes. Also, there's a solid chance it exists as a sequence within pi.
1
u/andy9775 Apr 29 '22 edited Apr 29 '22
Using Godel numbering one can assign a number to each program (or function or TM).
Proofs which use the halting set usually define the set as the index of a function which halts making the halting set, a set of numbers
1
1
1
u/fbidu Apr 29 '22
Here is a small python script for you to toy around with that idea
https://gist.github.com/fbidu/28dfb1949756dd81a788cd58345aecfd
run it, study it, break it. You'll find some amazing things following that train of thought!
0
u/shawntco May 02 '22
If everything is ultimately binary, does't that just make programs a specific number?
This is one of those unintentionally brilliant observations that usually only newbies ever have, I love it
1
u/Smooth_Measurement_1 May 02 '22
How was it unintentionally brilliant? How do you know it wasn't intentional? That's completely discrediting my intelligence by saying that I accidentally asked an intelligent question.....
-4
u/gruntmeister Apr 28 '22
If everything is ultimately binary, does't that just make programs a specific number?
Yes!
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.
We do store them as a number. What did you think we're storing them as? I don't remember ever having to type in "5000 pages of 1s and 0s" in my computer to run a computer program.
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?
Because computers, hard drives, cd's, dvd's, store data digitally. You might've heard the term.
Storage would be much less.
No. Please explain: unless you're still thinking about printing data out on paper, how would 57000443836 take less storage than 110101000101011111011011111110111100? It's the same number, the same amount of information. What storage are you talking about in the first place? Digital storage? Like hard drives?
→ More replies (1)
2.4k
u/captainAwesomePants Apr 28 '22
YES!
YES!
Good question. It's because it's really cheap to build a trillion tiny things that can reliably be either on or off, and it's much more expensive to build a bunch of things that can be in 10 different states. For example, if you wanted to store any number between 1 and 1,000,000, you could either do it with 6 counters that could store 10 values each, or you could do it with 20 counters that could store 2 values each, and it turns out that 20 counters storing 2 values each are much cheaper to make.
No. It's the same amount of information either way. It takes less space to write it on paper in decimal, but it's still the same total amount of information.
These are crazy IMPORTANT questions. "Oh my god information is just a number" is perhaps the foundational thought of computer science. It leads to Hilbert's "oh crap mathematical proofs can be a number" discovery, which led to Godel's incompleteness theorem, which is one of the most astounding, depressing, and important mathematical discoveries of the 20th century. It's a GREAT question to be thinking about.