Add Short Ints: 30064 + 30064 = -60128

  • Thread starter Thread starter Lightf
  • Start date Start date
  • Tags Tags
    Integers Short
AI Thread Summary
To calculate 30064 + 30064 as short integers, the result must be interpreted in the context of short int limits. The maximum value for a signed short int is 32,767, and adding 30064 to itself exceeds this limit, resulting in an overflow. The hexadecimal addition yields eae0, which, when interpreted as a short int, indicates a negative value due to the highest order bit being set. The correct interpretation of eae0 in two's complement gives -27360 in decimal. Understanding the two's complement representation is crucial for correctly determining the negative result.
Lightf
Messages
16
Reaction score
0

Homework Statement



The question is :

Converting to short int, calculate 30064 + 30064 as short integers.
Convert the answer to decimal ( the answer will be negative ).

Homework Equations



None.

The Attempt at a Solution



I converted 30064 to hex getting 7570.

I then added that to itself getting eae0.

But when i convert that back to dec I just get 60128 ? How am i suppose to get a negative number?
 
Physics news on Phys.org
Lightf said:

Homework Statement



The question is :

Converting to short int, calculate 30064 + 30064 as short integers.
Convert the answer to decimal ( the answer will be negative ).

Homework Equations



None.

The Attempt at a Solution



I converted 30064 to hex getting 7570.

I then added that to itself getting eae0.

But when i convert that back to dec I just get 60128 ? How am i suppose to get a negative number?

Since you're talking about short integers, I'm assuming you are talking about the short int data type in C or C++. Short ints are 32 bit signed numbers, which means that the largest positive short int is 32,767, or 0x7ffff. Adding 1 to this gives you 0x8000, which is -32,768.

Any short int whose highest order bit is 1 is considered to be negative.
 
So the answer would be :

7fff - eae0 = 6ae1

6ae1 - 8000 = -151f

which is -5497 in dec.

Is that the correct way of doing it? Thanks for the help.
 
You may want to look for "two's complement" in your textbook or on the net.
 
So eae0 is 1110101011100000 but the first 1 just means its a minus number so its -27360
 

Similar threads

Back
Top