Convert unsigned 16-bit int to signed 16-bit int in C #

I am writing a data parser for a robot controller, and what comes from the data log is a number in the range from 0 to 65535 (this is a 16-bit unsigned integer, if I'm not mistaken). I am trying to convert this to a 16-bit integer that will be displayed to the user (since this was the actual data type before he changed it).

Can someone give me a hand?

Example:

What values ​​should be (0, -1, -2, -3, -4)

What are the values ​​(0, 65535, 65534, 65533, 65532).

+5
source share
1 answer

Have you tried explicit casting?

UInt16 x = 65535;
var y = (Int16)x; // y = -1
+12
source

All Articles