如何将一个2位的byte数组转为1个int?
解决方案 »
- 怎么获取热敏打印机状态
- C# form程序,我想问下将formboderstyle设置为none后。
- 跪求,高手解决访问FTP服务器
- wse 3.0 认证 难题.
- 有没有高手能解释一下这段代码为何会导致DEP?(C#, .net 2.0)
- 抢分啦!关于C# for ORACLE 的问题
- 请问哪位有activereports for .net 3.0 注册机?
- 问一个引用类型和其垃圾回收的问题,请大家指点!谢谢!
- 一个小问题,关于ExecuteNonQuery()的
- 在dataGrid中,如何禁止用户自己添加新行?
- rdlc报表上的图像显示不出来,为红叉.
- 检索的时候,如何实现象百度搜索出来的界面效果,循环显示, winform
public int bytes2int(byte[] b)
{
int mask = 0xff;
int temp = 0;
int res = 0;
for (int i = 0; i < 2; i++)
{
res <<= 8;
temp = b[i] & mask;
res |= temp;
}
return res;
}
16进制的,将2个数合为一个10进制的int
int s;
byte bytes[2] = {12,12};
s = bytes[0] + bytes[1] << 8;
如果高位在前,低位在后,则
s = bytes[0] << 8 + bytes[1];