byte[] mySByte = new byte[myByte.Length];
for (int i = 0; i < myByte.Length; i++)
{
if (myByte[i] > 127)
mySByte[i] = (sbyte)(myByte[i] - 256);
else
mySByte[i] = (sbyte)myByte[i];
}
原理很简单,就是当 byte 小于 128 时其值保持不变,大于等于 128 时就将其减去 256。
byte[] mySByte = new byte[myByte.Length];
for (int i = 0; i < myByte.Length; i++)
{
if (myByte[i] > 127)
mySByte[i] = (sbyte)(myByte[i] - 256);
else
mySByte[i] = (sbyte)myByte[i];
}
原理很简单,就是当 byte 小于 128 时其值保持不变,大于等于 128 时就将其减去 256。