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 4 of 4

Thread: Double to Hex

  1. #1
    Member
    Join Date
    May 2013
    Posts
    165
    Thanks
    58
    Thanked 1 Time in 1 Post

    Default Double to Hex

    I am trying to convert the double 4270571936.0000000000d to a hex string using Double.toHexString() and the answer I'm getting is 0x1.fd17834p31, what does p stands for?

    The answer I'm expecting to get is 0x41efd17834000000 so not sure why it won't give me the correct answer?

    The following floating point Double to hex calculator shows the write answer right Floating Point to Hex Converter


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,585
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Double to Hex

    what does p stands for?
    Did you have any questions about the explanation in the API doc? If so, copy the part you don't understand, paste it here and ask the questions.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    May 2013
    Posts
    165
    Thanks
    58
    Thanked 1 Time in 1 Post

    Default Re: Double to Hex

    Is there any way in which I can get rid of the p so it does not print the hex string to the exponent?

    Basically I want it to print 0x41efd17834000000 instead of 0x1.fd17834p31.
    Last edited by keepStriving; May 8th, 2014 at 06:46 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,585
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Double to Hex

    I'd have to look at the API doc. I've never tried.

    Another way might be to use the writeDouble() method to write to a byte array output stream. The double would be the in the first 8 bytes of the array, use the Integer class's toHexString to convert the bytes to String.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. RGB to Hex
    By that_guy in forum AWT / Java Swing
    Replies: 6
    Last Post: March 11th, 2012, 08:36 PM
  2. [SOLVED] Read double from console without having to read a string and converting it to double.
    By Lord Voldemort in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 26th, 2011, 08:08 AM
  3. Hex to Integer Problem
    By TempSpectre in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 1st, 2010, 06:01 AM
  4. my Hex
    By wolfgar in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 27th, 2010, 04:31 PM
  5. decimal to hex
    By rsala004 in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 3rd, 2009, 01:16 AM