# Solving an ambiguity concerning unsigned and signed integers [duplicate]

I am taking a class in computer science and I am not sure about the following. When one transforms $$247_{10}$$ into its binary counterpart one gets $$11110111_2$$. However, the same binary number corresponds also to$$-9$$ when the 2-complement representation is considered. How does the computer know which of the two numbers we mean, or eventually how one can know which of the two numbers is meant ? If we provide to the machine $$-9$$ it is then clear how to proceed to get the binary, but after a certain number of arithmetic if the computer gets as a result $$11110111$$ how it will make it to provide the correct decimal number, i.e. 247 versus -9 ? Thanks.

• How does the computer know [what] we mean. It does not, and doesn't need to - just follow instructions. Sep 20, 2022 at 4:41
• The type of the data in memory is implied by the program that refers to it. $11110111$ could be taken for the numbers $-9$ or $243$, for the character $\le$ or yet other interpretations, depending on how the data has been declared. The type is not attached explicitly to the bytes. Sep 20, 2022 at 11:34