Saturday, April 12, 2014

Base converting program in Java


public class Base
{
public void decTobase(int n,int b)
{
if(n>0)
{
decTobase(n/b,b);
System.out.print(n%b);
}
}
public static void main(String args [])
{
Base a=new Base();
a.decTobase(15,2);
System.out.println();
a.decTobase(65,4);
System.out.println();
a.decTobase(511,8);
System.out.println();
}