Results 1 to 4 of 4
  1. #1
    rlzyoner is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default [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 au-fait 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

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default

    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 base-8 digits to y base-16 digits? since your bases are both powers of 2, how can you do the division and multiplication quicker?

  4. #4
    rlzyoner is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

Similar Threads

  1. How to find logarithm base 2 value in java
    By RJNARESH in forum Advanced Java
    Replies: 5
    Last Post: 03-19-2009, 11:12 PM
  2. [SOLVED] base directory for servlets
    By Nicholas Jordan in forum Java Servlet
    Replies: 11
    Last Post: 07-05-2008, 12:29 AM
  3. Conversions
    By apfroggy0408 in forum New To Java
    Replies: 3
    Last Post: 03-05-2008, 12:59 AM
  4. Replies: 1
    Last Post: 08-06-2007, 06:38 PM
  5. Connection to data base
    By Daniel in forum JDBC
    Replies: 2
    Last Post: 06-07-2007, 05:55 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
  •