我确实有一个包含一系列数字的字节数组...
t 阻止而不是其余的!
我怎样才能让所有块 4-8 都在Temp[]
??
元素 4-8(或实际上索引 3-7)是 5 个字节。不是 4。
您将源偏移量和计数混为一谈:
Buffer.BlockCopy(bResponse, 3, temp, 0, 5);
现在 temp 将包含 [23232]
.
如果你想要最后 4 个字节,那么使用这个:
Buffer.BlockCopy(bResponse, 4, temp, 0, 4);
现在 temp 将包含 [3232]
.
要将其转换为 int:
if (BitConverter.IsLittleEndian)
Array.Reverse(temp);
int i = BitConverter.ToInt32(temp, 0);
编辑:(在您的评论之后,[43323232]
实际上是{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
如果你想把它转换为一个int,那么上面的BitConverter示例仍然有效。