Java - Double Class toHexString() Method

Double class toHexString() method: Here, we are going to learn about the toHexString() method of Double class with its syntax and example. By Preeti Jain Last updated : March 23, 2024

Double class toHexString() method

  • toHexString() method is available in Double class of java.lang package.
  • toHexString() method is used to get the hexadecimal string representation of the given parameter [value] of double floating-point type.
  • toHexString() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
  • toHexString() method does not throw an exception at the time of conversion from double to Hexadecimal string.

Syntax

public static String toHexString(double value);

Parameters

  • double value – represents the double value to be converted.

Return Value

The return type of this method is string, it returns the hexadecimal string of the given parameter that represent the double value.

Example

// Java program to demonstrate the example 
// of toHexString(double value) method of Double class

public class ToHexStringOfDoubleClass {
    public static void main(String[] args) {
        // Variables initialization
        double d1 = 10.0;
        double d2 = 20.0;
        double d3 = 30.0;
        double d4 = Double.MAX_VALUE;
        double d5 = Double.MIN_VALUE;

        // Double instance creation
        Double value = new Double(d1);

        // It represents hexadecimal string of the given
        // double type d2 argument
        String s = value.toHexString(d2);

        // Display Hexadecimal String Representation
        System.out.println("value.toHexString(d2): " + s);

        // It represents hexadecimal string of the given
        // double type d3 argument
        s = value.toHexString(d3);

        // Display Hexadecimal String Representation
        System.out.println("value.toHexString(d3): " + s);

        // It represents hexadecimal string of the given
        // double type d4 argument
        s = value.toHexString(d4);

        // Display Hexadecimal String Representation
        System.out.println("value.toHexString(d4): " + s);

        // It represents hexadecimal string of the given
        // double type d5 argument
        s = value.toHexString(d5);

        // Display Hexadecimal String Representation
        System.out.println("value.toHexString(d5): " + s);
    }
}

Output

value.toHexString(d2): 0x1.4p4
value.toHexString(d3): 0x1.ep4
value.toHexString(d4): 0x1.fffffffffffffp1023
value.toHexString(d5): 0x0.0000000000001p-1022

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.