如何把byte数组中某几位的值以Int型返回?
比如收到的数据时一个byte数组,其中第4-7字节是一个DWORD型的数,请问C#中如何把这个数读出来?
多谢!
[解决办法]
byte[] _Bytes = new byte[100];
int _Value = BitConverter.ToInt32(_Bytes, 3);
[解决办法]
- C# code
byte[] buff = new byte[1024];byte* pStart = &buff[3];int* pValue = (int*)pStart;int value = *pValue;
[解决办法]
int value = Bytes[4] << 24 | Bytes[5] << 16 | Bytes[6] << 8 | Bytes[7];
or
int value = Bytes[7] << 24 | Bytes[6] << 16 | Bytes[5] << 8 | Bytes[4];