我从一个有符号字节数组开始并转换为无符号..所以打印结果正确吗?
byte[] unsigned = new byte[] {10,100,120,180,200,220,240};
sbyte[] signed = Utils.toSignedByteArray(unsigned);
和打印(我只是用 StringBuilder 附加它们):
签名:[10,100,120,-76,-56,-36,-16]
未签名:[10,100,120,180,200,220,240]
在哪里:
public static sbyte[] toSignedByteArray(byte[] unsigned){
sbyte[] signed = new sbyte[unsigned.Length];
Buffer.BlockCopy(unsigned, 0, signed, 0, unsigned.Length);
return signed;
}
如果我改成这个,我会得到相同的结果。
sbyte[] signed = (sbyte[])(Array)unsigned;
不应该 -128(有符号)变成 0,-118 变成 10,等等......而不是 10(有符号)= 10(无符号)!?
因为
sbyte -128 到 127
字节 0 到 255
所以??