请教:对位级别的逻辑操作 谢 C#:short 类型变量 i我想取i的某一位index是不是1..如何编写算法?...谁会啊..在线等您指教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private static bool CheckBit(int i,int bit) { //MessageBox.Show( CheckBit(4,3).ToString()); int x=(int)System.Math.Pow(2,bit-1); return((i&x)!=0); } private static bool CheckBit(int i,int bit) { return (((i>>(bit-1))&1)!=0); } class Class1 { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(string[] args) { // // TODO: 在此处添加代码以启动应用程序 // short i = 2; ushort index = 3; bool res = check(i,index); Console.WriteLine("["+index.ToString()+"] = "+res.ToString()); } public static bool check(short i,ushort index) { return (((i >> (index-1)) & (short)1) == 1); } }expl:short i = 2;——0000000000000010上述check()中,将上面的1这位视作第二位 js如何调用 自定义控件 前台值 关于picturebox的图像重绘问题 C#graphics 关于JS中的Object类问题 using 写在程序里,和写在最上面,会不会有性能的不同? 如何对窗体中所有控件序列化? 如何用c#获取进程打开的端口? winform可否实现这样的功能 正则表达式匹配问题 PING命令小工具出错小白求教 高分求救,关于dropdownlist的问题,在线等待中,帮顶有分 help,怎样把按钮设置成缺省的按钮?
{
//MessageBox.Show( CheckBit(4,3).ToString());
int x=(int)System.Math.Pow(2,bit-1);
return((i&x)!=0); }
{
return (((i>>(bit-1))&1)!=0); }
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
short i = 2;
ushort index = 3;
bool res = check(i,index);
Console.WriteLine("["+index.ToString()+"] = "+res.ToString());
} public static bool check(short i,ushort index)
{
return (((i >> (index-1)) & (short)1) == 1);
}
}
expl:
short i = 2;——0000000000000010
上述check()中,将上面的1这位视作第二位