C#之BitConverter.ToInt16
byte[] bytes =
{
1,3
};
short s = BitConverter.ToInt16(bytes,0);
Console.WriteLine(s);

从低位到高位填充:
0000 0003 0000 0001
3*2^8+1=769;
byte[] bytes =
{
0x21,0x31
};
short s = BitConverter.ToInt16(bytes,0);
Console.WriteLine(s);

从低位到高位填充:
0003 0001 0002 0001
3212+1*28+22^4+1=12577
byte[] bytes =
{
0xAB,0xCD
};
short s = BitConverter.ToInt16(bytes,0);
Console.WriteLine(s);

首先,D->1101,C->1100,B->1011,A->1010,
组装到一起为:
CDAB,即1100 1101 1010 1011
最高位为1,表明是负数,值为原码的反码+1,
反码为0011 0010 0101 0100,
补码为0011 0010 0101 0101,
为20+22+24+26+29+212+2^13=12885,
但为负数,即为-12885
#####
愿你一寸一寸地攻城略地,一点一点地焕然一新
#####

浙公网安备 33010602011771号