Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: BASE CONVERSION

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool BASE CONVERSION

    Can Anyone suggest me a simpler algorithm for converting any base number to base 10??


  2. #2
    Junior Member
    Join Date
    May 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: BASE CONVERSION

    USING ITERATION PLZ!!!

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: BASE CONVERSION

    suggest me a simpler algorithm
    Simpler than what?

    db

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: BASE CONVERSION

    At this point it doesn't matter that it is simpler. I just need an Iterative way to implement any base conversion to a base 10.

  5. #5
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: BASE CONVERSION

    Take a pen and paper. Do some base conversion math, placing each step on a separate line. When you're comfortable that you know what steps are needed, write Java code that carries out the same steps.

    If and only if you can't get the right results, post your best attempt and we'll take a look.

    db

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: BASE CONVERSION

    If you are unsure how to comvert numbers by hand, see PlanetMath: base conversion

  7. #7
    Junior Member
    Join Date
    May 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: BASE CONVERSION

    ok thanks! This is what I got and I actually think that it works
     public static String convert(String num,int b)
                    {
                         int k= num.length();   
                         int num10=0;
                         for(int i=0; i<k ;i++)
                         {
                             String r= num.charAt(k-(i+1))+"";
                             int NUM1 = Integer.parseInt(r);
                             num10 += (NUM1 *power(b,i));
     
                          }
    return num10+"";
    }
    Last edited by helloworld922; November 13th, 2010 at 03:47 PM.

Similar Threads

  1. Base Conversion
    By Pingu in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 22nd, 2011, 02:15 PM
  2. Doubts Over Base Class
    By rakesh86shankar in forum Object Oriented Programming
    Replies: 1
    Last Post: September 29th, 2010, 09:04 AM
  3. Simple Data Base.
    By Reese in forum The Cafe
    Replies: 14
    Last Post: August 2nd, 2010, 02:23 PM
  4. How to place icon on a picture base on (x,y) axis
    By FaintSmile in forum Java Theory & Questions
    Replies: 1
    Last Post: July 13th, 2010, 07:27 AM
  5. binary conversion..
    By chronoz13 in forum Java Theory & Questions
    Replies: 8
    Last Post: September 16th, 2009, 10:47 AM