One version is
short value = unchecked((short)0x8010);
Other versions like below will not work, and will throw an exceptions
short value = Convert.ToInt16(0x8010);
short value = (short)(0x8010);
Is there any other version without unchecked keyword?
Updated: expected is negative value of -32752
The following will work to convert all
ushortvalues which fit intoshortand replace all values which don’t withshort.MaxValue. This is lossy conversion though.If you are looking for a straight bit conversion you can do the following (but I wouldn’t recommend it)