Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 26
  1. #11
    Join Date
    Apr 2004
    Location
    Saskatchewan, Canada
    Posts
    1,356
    ok i am jsut going to write method that converts a number to base 10 then add the two base 10 numbers together. But now i am having another problem...how the heck do you do exponents in java cause ^ doesnt work...

  2. #12
    Join Date
    Jul 2003
    Location
    UK
    Posts
    245
    edit:

    Last edited by NeoMT; 01-18-2005 at 06:25 PM.

  3. #13
    Join Date
    Sep 2004
    Posts
    57
    Originally posted by shockertwin
    how the heck do you do exponents in java cause ^ doesnt work...
    http://java.sun.com/j2se/1.4.2/docs/...lang/Math.html

    use pow

  4. #14
    Join Date
    Apr 2004
    Location
    Saskatchewan, Canada
    Posts
    1,356
    ok thsi isnt working and neo thanks for the help but what you are suggesting is completely irrelavent to what i am asking. i kow that using those convert, but they also change the number, which i dont want to happen.

    HERE IS WHAT NEEDS TO BE DONE:

    The user types in a value, which will be read as a string. I need to convert this string to a number base 7 WITHOUT CHANING THE VALUE OF THE NUMBER.

    so if the user types in 12, i need to convert that number to base 7 without changing the actual value, and neither of those things do that neo, they both change the number.

  5. #15
    Join Date
    Jul 2003
    Location
    UK
    Posts
    245
    sorry about confusing you. i'll try some test and see what happen.

  6. #16
    Join Date
    Apr 2004
    Location
    Saskatchewan, Canada
    Posts
    1,356
    well i jsu tdid some tests and when i parsed an into to base 7 and then added them together it didnt treat them as base it, it treated them as base 10. This is retarded.

  7. #17
    Join Date
    Jul 2003
    Location
    UK
    Posts
    245
    to convert base 7 to base 10

    Code:
    int temp = 0;
    int base = 0;
    String num1 = "16";
    for (int i = num1.length()-1;i>=0;i--)
    {
    	int t1 = Integer.parseInt(""+num1.charAt(i));
    	int t2 = (int)(Math.pow(7,base));
    	temp+= t1*t2;
    	base++;
    }
    System.out.println(temp);
    use Integer.toString(result, 7) to convert back to base 7.

    EDITED
    Last edited by NeoMT; 01-18-2005 at 07:34 PM.

  8. #18
    Join Date
    Sep 2004
    Posts
    57
    Originally posted by shockertwin
    well i jsu tdid some tests and when i parsed an into to base 7 and then added them together it didnt treat them as base it, it treated them as base 10. This is retarded.
    It's retarded that it doesn't store things in base 7? It takes the nmber as the base you tell it to and stores it as a base 10. They provided a method for inputing in any base you want and methods for outputing in common bases (2,8,16). If you want to output base 7 be prepared to do a little work. Computers work in 2s, and humans work in 10s. There really isn't a big demand for them to design for the other bases.

    The goal of your assignment was probably trying to get you to create your own method for displaying it in base 7.

  9. #19
    Join Date
    Apr 2004
    Location
    Saskatchewan, Canada
    Posts
    1,356
    sorry, i fly off the wall when my programs dont work. thanks neo for your help, and your too stabin. Also i will give your converting ot base 7 a shot neo. i gave up for teh moment though. The reason it is retarded is because our class has had absolutely no introduction to bases or conversion of this sort at all. we have only done simple stuff with basic numbers and storage. Thanks again guys. Do i need to import java.math.somethign in order for that to work neo?

    edit** lol neo i ws soo close. all i needed was to bring in that temp variable and i could have had it figured out. But since it is there i will use it to my advantage and try to write my own that based on it. thanks bud.

  10. #20
    Join Date
    Sep 2004
    Posts
    57
    It's java.lang.math, you shouldn't have to import things that start with java.lang

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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