Results 1 to 2 of 2
  1. #1
    amarchandar is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default help needed urgently

    hi friends,
    i'm trying to write a program that converts decimal value into any (binary,octal and hexa decimal)
    i'm printing the result but i coudn't convert hexa decimal value
    please help me
    here is my code
    public class decx
    {
    public static void main(String args[])
    {
    String output=decx.decToBase(28,2);
    String output1=decx.decToBase(234,8);
    String output2=decx.decToBase(2989,16);

    System.out.println(output);
    System.out.println(output1);
    System.out.println(output2);
    }
    static String decToBase(int n,int radix)
    {
    String str=" ";
    String str1="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int i;
    int rem;
    while(n!=0)
    {
    i=n/radix;
    rem=n%radix;
    System.out.println(rem);
    n=i;
    if(rem<=9)
    {
    str=str+rem;
    }
    else
    {
    rem=str1.charAt(rem);
    str=str+rem;
    }
    }
    return str;
    }
    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. JSP (urgently)
    By G.Ajay Kumar in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-19-2009, 05:43 AM
  2. Replies: 2
    Last Post: 01-27-2009, 03:35 PM
  3. Help!urgently please
    By kevN in forum AWT / Swing
    Replies: 10
    Last Post: 01-09-2009, 05:37 PM
  4. Help needed, urgently!
    By Emfy in forum New To Java
    Replies: 5
    Last Post: 12-27-2008, 03:06 PM
  5. please help urgently
    By ananas7777 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 02:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •