日期:2014-05-17 浏览次数:21155 次
public void Func(int input)
{
int m = 1;
for(int i = 1;i<32;i++)
{
if(m & input == m)
Console.WriteLine(m);
m = m << 1;
}
}
/// <summary>
/// 把一个任意正整数拆解成几个是2的n次方的数
/// </summary>
/// <param name="num">传入的正整数</param>
/// <returns>结果字符串:传入正整数51,输出结果为"2的0次方+2的1次方+2的4次方+2的5次方" </returns>
public string Fun(int num)
{
string outputStr = "";
string ss = Convert.ToString(num, 2);
List<char> list = list = new List<char>();
foreach (char s in ss)
{
list.Add(s);
}
int j = 0; //控制幂
for (int i = list.Count -&nbs