用i= 1与该数&,大于0则输出该i。然后i = i * 2.循环做。

解决方案 »

  1.   

    应该有直接转换的方法吧?查ing
      

  2.   

    随机输入的数为N
    for(;n!=0;)
    {
      for(a=1;a*2<=n;a=a*2);
      n=n-a;
      输出a;
    }
      

  3.   

    public  ArrayList DtoB(int i)
    {   
            ArrayList result = new ArrayList();
        ArrayList array = new ArrayList();
          bool b = true;
            int j,m;
         while(b)
     {
           j = i%2 ;
            m = i/2;
         array.Add(j);
         if(m ==0)
         b =false;
            
     }
       array.Reverse();
       m = array.Count;
      j= 0;
       while(m>0)
      {  
           if(array.Item[j].Value ==1)
         result.Add(array.Item[j].Value*(m-1));
         j++;
          m--;
      }
      return result ;
       
    }
      

  4.   

    上面的有问题:
    public  ArrayList DtoB(int i)
    {   
            ArrayList result = new ArrayList();
        ArrayList array = new ArrayList();
          bool b = true;
            int j=i,m=i;
         while(b)
     {
           j = j%2 ;
            m = m/2;
         array.Add(j);
         if(m ==0)
         b =false;
            
     }
       array.Reverse();
       m = array.Count;
      j= 0;
       while(m>0)
      {  
           if(array.Item[j].Value ==1)
         result.Add(array.Item[j].Value*(m-1));
         j++;
          m--;
      }
      return result ;
       
    }
      

  5.   

    using System;namespace ConsoleApplication4
    { { [STAThread]
    static void Main(string[] args)
    {
    int Num=4111,a;
    for(;Num!=0;)
    {
    for(a=1;a*2<=n;a=a*2);
    Num=Num-a;
    Console.Write("{0}+",a);
    } }
    }
    }