java中byte和.net中byte转换

来源:互联网 发布:双色球关注数据采集 编辑:程序博客网 时间:2024/06/06 00:40

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。

 

原创粉丝点击