Home » Java programming language

Java Double class longBitsToDouble() method with example

Double class longBitsToDouble() method: Here, we are going to learn about the longBitsToDouble() method of Double class with its syntax and example.
Submitted by Preeti Jain, on September 24, 2019

Double class longBitsToDouble() method

  • longBitsToDouble() method is available in java.lang package.
  • longBitsToDouble() method is used to return the double value corresponding to the given long bit denotation followed by IEEE 754 double floating-point standards.
  • longBitsToDouble() 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.
  • longBitsToDouble() method does not throw an exception at the time of representing bits.

Syntax:

    public static double longBitsToDouble(long bits_rep);

Parameter(s):

  • long bits_rep – represents the long integer value.

Return value:

The return type of this method is double, it returns the bits that represent the long integer value.

Note:

  • If we pass "0x7ff0000000000000L", it returns the value "positive infinity".
  • If we pass "0xfff0000000000000L", it returns the value "negative infinity".

Example:

// Java program to demonstrate the example 
// of longBitsToDouble(long bits_rep)
// method of Double class

public class LongBitsToDoubleOfDoubleClass {
    public static void main(String[] args) {
        // Variables initialization
        double d1 = 18.20;
        double d2 = 19.20;

        // Display value1,value2 values
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);

        // Double instance creation
        Double value1 = new Double(d1);
        Double value2 = new Double(d2);


        // It returns the double value denoted by the given bit denotation 
        //by calling value1.longBitsToDouble(124568)
        double result1 = value1.longBitsToDouble(124568);

        // It returns the double value denoted by the given bit denotation 
        //by calling value1.longBitsToDouble(124568)

        double result2 = value2.longBitsToDouble(0xfff0000000000000L);

        // Display result1,result2 values
        System.out.println("value1.longBitsToDouble(124568): " + result1);
        System.out.println("value2.longBitsToDouble(0xfff0000000000000L): " + result2);
    }
}

Output

d1: 18.2
d2: 19.2
value1.longBitsToDouble(124568): 6.1545E-319
value2.longBitsToDouble(0xfff0000000000000L): -Infinity





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.