I'm getting a hex string that needs to be converted to a signed 8-bit integer. Currently I'm converting using Int16/Int32, which will obviously not give me a negative value for an 8-bit integer. If I get the value 255 in Hex, how do I convert that to -1 in decimal? I assume I want to use an sbyte, but I'm not sure how to get that value in there properly.
+1
A:
You need to perform an unchecked
cast, like this:
sbyte negativeOne = unchecked((sbyte)255);
SLaks
2010-09-14 00:54:16
Why was this downvoted?
SLaks
2010-09-14 02:49:57
A:
My solution was to put the first take the first 8 bits of the 16 bit integer and store them in an sbyte.
alexD
2010-10-09 22:07:55