Search code examples
c#type-conversionbytesigned

Convert one byte to signed byte or int


oxfc is negative but I have it as a byte and its value is 252, is there any way to convert it to signed byte or int?

I found this method:

(BitConverter.ToInt16(new byte[2] { 0, 0xfc }, 0) / 256).ToString()

But is there any better way?


Solution

  • You can simply cast it:

    byte b = 0xfc;
    sbyte s = unchecked((sbyte)b);