'How to initialize 16 bit int in c#?
I'm writing a datalog parser for a robot controller, and what's coming in from the data log is a number in the range of 0 - 65535 (which is a 16 bit unsigned integer if I'm not mistaken). I'm trying to convert that to a signed 16 bit integer to display to the user (since that was the actual datatype before the logger changed it).
Solution 1:[1]
Try using explicit casting.
Using unchecked here avoids a crash if [X] Check for Arithmetic Overflow is on:
UInt16 x = 65535;
Int16 y = unchecked((Int16)x);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rajon Tanducar |
