首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么把byte数组中某几位的值以Int型返回

2012-07-31 
如何把byte数组中某几位的值以Int型返回?比如收到的数据时一个byte数组,其中第4-7字节是一个DWORD型的数,

如何把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];

热点排行