Link to home
Start Free TrialLog in
Avatar of maxy88
maxy88

asked on

Convert int32 to int16


Hello EE,

   I need to convert an int32 to an int16. If I use the System.Convert.ToInt16(myInt32) I get an overflow exception for numbers over 32767. Does anyone know how to convert from an int32 which is less than 65,535 into an int16?

Cheers,
Max.
Avatar of adathelad
adathelad
Flag of United Kingdom of Great Britain and Northern Ireland image

You can't - an int16 can only store numbers from -32768 and 32767
That should have said:
an int16 can only store numbers from -32768 to 32767

It's just not possible to store numbers greater than 32767 in an int16
Avatar of maxy88
maxy88

ASKER


Are you saying there is no way to convert from an int32 with value 65529 to an int16 whose value should be -7

Cheers,
Max.
ASKER CERTIFIED SOLUTION
Avatar of Expert1701
Expert1701

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maxy88

ASKER


Hey it actually worked....(Why didn't I try this first instead of System.Convert.ToInt16) LOL. Thanks!
Apologies - completely didn't get what you was asking!