Casting an int to a short gives unexpected results

Viewed 2178

I'm a little confused about loss information on numeric types in C#.

When i do this:

int x = 32780;
short y = (short)x;

I have the result: -32756 for y and not the expected 32767. Why? How this is calculated?

Range of short: -32768 to 32767 Range of int: -2,147,483,648 to 2,147,483,647

5 Answers
Related