转换类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace tento2
{
class ConvertUtil
{
public static string get2Value(int tenValue)
{
String ret = "";
while (tenValue / 2 != 0)
{
ret = tenValue % 2 + ret;
tenValue /= 2;
}
if (tenValue != 0)
ret = tenValue + ret;
return ret;
}
public static string get2ValueRec(int tenValue)
{
if (tenValue / 2 == 0 && tenValue!=0)
{
return "" + tenValue;
}
return get2ValueRec(tenValue / 2) + tenValue % 2;
}
}
}
主程序类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace tento2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(ConvertUtil.get2ValueRec(10));
Console.ReadLine();
}
}
}
程序输出:
1010