How does a computer determine the data type of a byte?

Question Detail: 
For example, if the computer has 10111100 stored on one particular byte of RAM, how does the computer know to interpret this byte as an integer, ASCII character, or something else? Is type data stored in an adjacent byte? (I don’t think this would be the case as this would result in using twice the amount of space for one byte.)
I suspect that perhaps a computer does not even know the type of data, that only the program using it knows. My guess is that because RAM is RAM and therefore not read sequentially, that a particular program just tells the CPU to fetch the info from a specific address and the program defines how to treat it. This would seem to fit with programming things such as the need for typecasting.
Am I on the right track?

Asked By : Airhead
Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/45794

Answered By : Yuval Filmus

Your suspicion is correct. The CPU doesn’t care about the semantics of your data. Sometimes, though, it does make a difference. For example, some arithmetic operations produce different results when the arguments are semantically signed or unsigned. In that case you need to tell the CPU which interpretation you intended.
It is up to the programmer to make sense of her data. The CPU only obeys orders, blissfully unaware of their meaning or goals.

Leave a Reply

Your email address will not be published. Required fields are marked *