# Thread: Value bigger than the signed value

1. ## Value bigger than the signed value

The program is a bigger program but the summary of program is

Code:
```int main(void)
{
signed int data1;
data1 = 32785;
return 0;
}```
I know that data1 is signed value and hence the maximum value is 32767. When i store 32785 will the value of data1 be 32767-32785 = -18? But the correct value is -32751. How was it arrived? Please help.

2. Lots of things going on here, but in summary, if 'int' is 16 bits, and you have a overflow the answer will be wrong by 2^16, or 65536.

So what is 32785-65536? −32,751

3. Thank you for the reply. The complete program is

Code:
```uint32_t startupRamp=0;
int16_t theta=0;
void CalculateTheta(void)
{
/* Then ramp up till the end */
if (startupRamp < END_SPEED)
{
startupRamp += 10;
}
theta += (int16_t)(startupRamp >> 10);
}```
So my understanding and sequence of steps are
a. When startupRamp is 32785, its hex value is 0x8011.
b. The MSBit is 1 hence it is negative value.
c. Compiler will store the 2's complement number is 32751.
d. The computer will add a negative sign (since the MSBit is 1) and assign the value of -32751. Is it correct? Please help.

4. Originally Posted by CTest123
Thank you for the reply. The complete program is

Code:
```uint32_t startupRamp=0;
int16_t theta=0;
void CalculateTheta(void)
{
/* Then ramp up till the end */
if (startupRamp < END_SPEED)
{
startupRamp += 10;
}
theta += (int16_t)(startupRamp >> 10);
}```
So my understanding and sequence of steps are
a. When startupRamp is 32785, its hex value is 0x8011.
b. The MSBit is 1 hence it is negative value.
c. Compiler will store the 2's complement number is 32751.
d. The computer will add a negative sign (since the MSBit is 1) and assign the value of -32751. Is it correct? Please help.
It's way easier than that. For 16-bit signed numbers the most significant bit has a 'place value' of -32768, rather than the 32768 it would have in an unsigned (or longer) value.

So 0x8011 as a 16-bit unsigned decimal = 32768+1*16+1 = 32785
and 0x8011 as a 16-bit signed decimal = -32768+1*16+1 = -32751

5. Thank you that is really helpful.