using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BigPower
{
class Program
{
static void Main(string[] args)
{
int d = 9;
Console.WriteLine(Convert.ToString(d, 2));
Console.WriteLine(TestBit(d, 0));
Console.WriteLine(TestBit(d, 1));
Console.WriteLine(TestBit(d, 2));
Console.WriteLine(TestBit(d, 3));
Console.Read();
}
// 判断整数的第i位置是否为1 (i从0开始)
public static bool TestBit(int d, int i)
{
int b = (d >> i) & 1;
return b == 1;
}
}
}
运行效果