在C#中如何进行移位操作?

jasonhrs 2003-11-18 03:02:31
比如我现在要用C#开发一个单片机的虚拟机,是16位的,我用Uint16来表示单片机里的内存,但不知如何去移位,请各位大侠赐教!
...全文
332 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ms44 2003-11-18
  • 打赏
  • 举报
回复
同C
wolve 2003-11-18
  • 打赏
  • 举报
回复
public class BitHelper
{
const int LongOne =0x1;
public static bool[] GetBitArray(int exp)
{
int length=(int)Math.Ceiling(Math.Log(exp,2));
bool[] result=new bool[length];
int i;
for(i=0;i<length;i++)
{
result[i]=(exp & (LongOne<<i))>0;
}

return result;

}

public static int GetValue(bool[] items)
{
int result=0;
int i;
for(i=0;i<items.Length;i++)
{
if(items[i])
{
result=result+(LongOne<<i);
}
}

return result;
}
}
}
KentYu 2003-11-18
  • 打赏
  • 举报
回复
<<
>>
a<<=b 相当与a=a<<b
ETstudio 2003-11-18
  • 打赏
  • 举报
回复
移位运算符>> 和<<
polarlm 2003-11-18
  • 打赏
  • 举报
回复
<<
>>

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧