如何将0xf转换为1111 有现成的方法吗  还是要自己编程实现

解决方案 »

  1.   

    System.Math命名空间应该有相应的转换函数
      

  2.   

    是要把字符串"0xf"转换成字符串"1111"吗?首先把它转换成整数:string s = "0xf";
    int i = System.Convert.ToInt32(s, 16);
      

  3.   

    using System;class Test
    {
      static void Main()
      {
       string s0 = Console.ReadLine();
        int i = Convert.ToInt32(s0, 16);
        string s1 = "";
        while (i > 0)
        {
         s1 = (i % 2).ToString() + s1;
         i /= 2;
        }
        Console.WriteLine("{0} = {1}", s0, s1);
      }
    }
      

  4.   

    算法:StringBuilder sb = new StringBuilder()
    while ( i > 0 )
    {
      sb.Append( (i%2).ToString() );
      i /= 2
    }结果可能是反的,如果反了,可以用字符串反转算法或者用Insert代替Append。