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...
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...
edit:
Last edited by NeoMT; 01-18-2005 at 06:25 PM.
http://java.sun.com/j2se/1.4.2/docs/...lang/Math.htmlOriginally posted by shockertwin
how the heck do you do exponents in java cause ^ doesnt work...
use pow
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.
sorry about confusing you. i'll try some test and see what happen.
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.
to convert base 7 to base 10
use Integer.toString(result, 7) to convert back to base 7.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);
EDITED
Last edited by NeoMT; 01-18-2005 at 07:34 PM.
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.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.
The goal of your assignment was probably trying to get you to create your own method for displaying it in base 7.
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.
It's java.lang.math, you shouldn't have to import things that start with java.lang