Results 1 to 4 of 4
Thread: [SOLVED] Base conversions
 12102008, 01:21 AM #1Member
 Join Date
 Jul 2008
 Posts
 7
 Rep Power
 0
[SOLVED] Base conversions
Howdy,
Not so much a question about code but logic.
I would like some advice on base conversions.
I would like to implement a utility that can convert from base8 to base16.
I'm not to aufait with this and was wondering would it be easiest to convert to say base2 and then from base2 to base16 or should i try to convert directly from base8 to base16.
Thanks
 12102008, 02:00 AM #2Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
 12102008, 08:16 AM #3Senior Member
 Join Date
 Nov 2008
 Posts
 286
 Rep Power
 13
If this isn't a programming exercise, look at Integer.parseInt() and Integer.toString(), both of which take a base parameter to convert from and to a given string representations of the number in a given base. (Even if it is a programming exercise, you might want to look at the source code and see how these methods are implemented, of course...)
If you're implementing it yourself, then yes you may want to think about optimising it for your specific conversion. You're going from base 8 to base 16:
 think about how many bits are in an octal (base 8) digit and how many bits in a hex (base 16) digit. How many digits in each base do you need before a whole number of base 8 digits has the same number of bits as a whole number of base 16 digits?
 when you've decided how many digits at a time you need to process from the source number, how do you extract those digits and convert them into an integer that the computer can do maths on?
 what's the formula/method you'll need to go from x base8 digits to y base16 digits? since your bases are both powers of 2, how can you do the division and multiplication quicker?Neil Coffey
Javamex  Java tutorials and performance info
 12102008, 01:40 PM #4Member
 Join Date
 Jul 2008
 Posts
 7
 Rep Power
 0
Similar Threads

How to find logarithm base 2 value in java
By RJNARESH in forum Advanced JavaReplies: 5Last Post: 03192009, 11:12 PM 
[SOLVED] base directory for servlets
By Nicholas Jordan in forum Java ServletReplies: 11Last Post: 07052008, 12:29 AM 
Conversions
By apfroggy0408 in forum New To JavaReplies: 3Last Post: 03052008, 12:59 AM 
Problems when I try to connect to data base
By gabriel in forum JDBCReplies: 1Last Post: 08062007, 06:38 PM 
Connection to data base
By Daniel in forum JDBCReplies: 2Last Post: 06072007, 05:55 AM
Bookmarks