0

我确实有一个包含一系列数字的字节数组...

t 阻止而不是其余的!

我怎样才能把所有的 4-8 块都放进去Temp[]??

4

1 回答 1

2

Elements 4-8 (or in reality index 3-7) is 5 bytes. Not 4.
You have the source offset and count mixed up:

Buffer.BlockCopy(bResponse, 3, temp, 0, 5);

Now temp will contain [23232].

If you want the last 4 bytes then use this:

Buffer.BlockCopy(bResponse, 4, temp, 0, 4);

Now temp will contain [3232].
To convert this to an int:

if (BitConverter.IsLittleEndian)
  Array.Reverse(temp);

int i = BitConverter.ToInt32(temp, 0);

Edit: (After your comment that [43323232] actually is {43, 32, 32, 32})

var firstByte = temp[0];   // This is 43
var secondByte = temp[1];  // This is 32
var thirdByte = temp[2];   // 32
var fourthByte = temp[3];  // 32

If you want to convert this to an int then the BitConverter example above still works.

于 2012-12-18T09:22:53.217 回答