# Important note

I know that this question may seem too simple for you scientists; however, here is the best place that I know to post it.

# Question

Suppose we have an int with all bits being 0, except for the last which is 11101000. How does my computer understand to return its two's complement i.e. -24 as value and not its original value i.e. 232?

# Edit: Question Details

I have written the following simple C++ code which shows unsafe conversions:

int main()
{
double d = 1000;
{
int i = d;
char c = i;
cout << c;
}
}


The code returns -24 for c while the last byte of i which is the value of c is 11101000; Actually -24 is its two's complement, i.e. 00011000.

• What makes you think the computer understands that? Can you give us more context? Computers don't "understand" anything, so you must be interpreting some behavior you have observed; can you edit your question to explain what that is and the basis for your inferences? – D.W. Jun 13 at 21:41
• Does this answer your question? Signed and unsigned numbers – Yuval Filmus Jun 13 at 21:42
• @D.W. --- Thanks, I edited it. – Alish Jun 14 at 6:59
• @YuvalFilmus --- I read only the accepted answer, but it doesn't seem to answer my question. – Alish Jun 14 at 7:01
• @Alish. Is your question "why is the returned value equal to the the integer represented by the last byte of (the representation of) 1000?" or "How does the computer know to print a the characters $\texttt{-24}$ from the byte 11101000? (or, more generally, any number from its representation in two's complement)" – Steven Jun 14 at 7:15