Reputation: 1
How does a computer know that it's an integer, not a memory address or not an ascii?
How does a computer knows it, to interpret it in the right way?
Upvotes: 0
Views: 39
Reputation: 12356
The computer really doesn't. It is the program that must "know". Programs, in addition to just storing the data in memory, also store the variable type.
A computer is smart enough to know how to interpret bits. Computer hardware architectures are responsible for interpreting memory endian type (little or big endian) and also the word size (8 bit, 16 bit, 32 bit, 64 bit). Hardware generally can interpret these types of values. It does not really know anything about whether it is an integer, memory address, or ASCII.
Upvotes: 0
Reputation: 881563
A computer generally doesn't know (unless you have some advanced architecture where each memory location has a tag value indicating what's stored there). All it stores and retrieves are bits.
Programs know how to interpret those bits because they were told by the programmer how to do so. Assuming the programmer was competent of course :-)
Upvotes: 1