现在要把一个int数(32位)的4个字节倒置,有下面两种写法。不知道为什么,第一种写法是正确的,第二种写法确报错
public static int reverseInt(int i)
{
int t = (((i & -0x01000000) >> 24) & 0xff)
| ((i & 0xff0000) >> 8)
| ((i & 0xff00) << 8)
| ((i & 0xff) << 24); return t;
} public static int reverseInt2(int i)
{
int t = (((i & 0xff000000) >> 24) & 0xff)
| ((i & 0xff0000) >> 8)
| ((i & 0xff00) << 8)
| ((i & 0xff) << 24); return t;
}我是在VS2005里用C#写的,报的错误如下:
Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
请高手指教!!
public static int reverseInt(int i)
{
int t = (((i & -0x01000000) >> 24) & 0xff)
| ((i & 0xff0000) >> 8)
| ((i & 0xff00) << 8)
| ((i & 0xff) << 24); return t;
} public static int reverseInt2(int i)
{
int t = (((i & 0xff000000) >> 24) & 0xff)
| ((i & 0xff0000) >> 8)
| ((i & 0xff00) << 8)
| ((i & 0xff) << 24); return t;
}我是在VS2005里用C#写的,报的错误如下:
Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
请高手指教!!
解决方案 »
- skype sidetone 回音消除与噪音抑制
- c# 操作 word中的文本框
- 关于winform中有效位数的函数
- 急!急!急!因为载的都是DLL文件,现求ZedGraph源码,谢谢!
- 请问:关于C# WINForm方面的书有什么?
- DataGrid 的排序问题? 急问,求助..........................................
- 请教关于打印跳转的问题。help!!!!!
- 鼠标钩子问题
- 想写个类继承SocketAsyncEventArgs,但是遇到个事件绑定问题
- 关于ListBox
- 错误提示:找不到存储过程,问题是存储过程有啊~
- 新手的苯问题,有耐心的帮忙解决一下,谢过
它可以是uint类型也可以是long类型。
不过你可以这么写
unchecked
{
int t = (((i & (int)0xff000000) >> 24) & 0xff)
| ((i & 0xff0000) >> 8)
| ((i & 0xff00) << 8)
| ((i & 0xff) << 24);
}