Search code examples
c#.netintegerhexsigned

How do I convert hex string into signed integer?


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.


Solution

  • My solution was to put the first take the first 8 bits of the 16 bit integer and store them in an sbyte.