【发布时间】:2023-04-01 17:26:01
【问题描述】:
oxfc 是负数,但我将它作为 byte,其值为 252,有没有办法将其转换为签名的 byte 或 int?
我找到了这个方法:
(BitConverter.ToInt16(new byte[2] { 0, 0xfc }, 0) / 256).ToString()
但是有没有更好的方法?
【问题讨论】:
标签: c# type-conversion byte signed
oxfc 是负数,但我将它作为 byte,其值为 252,有没有办法将其转换为签名的 byte 或 int?
我找到了这个方法:
(BitConverter.ToInt16(new byte[2] { 0, 0xfc }, 0) / 256).ToString()
但是有没有更好的方法?
【问题讨论】:
标签: c# type-conversion byte signed
你可以简单地投射它:
byte b = 0xfc;
sbyte s = unchecked((sbyte)b);
【讨论】: