示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TSortTest
{
class Program
{
static void Main(string[] args)
{
for (int i = -2; i <= 16; i++)
Console.WriteLine("{0}={1}", i, IsTwoPower(i));
Console.Read();
}
// 判断x是否为2的阶次方
public static bool IsTwoPower(int x)
{
return (x > 0) && (x & (x - 1)) == 0;
}
}
}