Home » Java programming language

Java Float class floatToIntBits() method with example

Float class floatToIntBits() method: Here, we are going to learn about the floatToIntBits() method of Float class with its syntax and example.
Submitted by Preeti Jain, on October 08, 2019

Float class floatToIntBits() method

  • floatToIntBits() method is available in java.lang package.
  • floatToIntBits() method follows IEEE 754 floating-point standards and according to standards, it returns the bits representation that denotes floating-point value.
  • floatToIntBits() 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.
  • floatToIntBits() method does not throw an exception at the time of representing bits.

Syntax:

    public static int floatToIntBits(float f);

Parameter(s):

  • float f – represents the single precision floating point value.

Return value:

The return type of this method is float, it returns the bits that represent the single precision floating-point value.

  • If we pass "positive infinity", it returns the value "0x7f800000".
  • If we pass "negative infinity", it returns the value "0xff800000".
  • If we pass "NaN", it returns the value "0x7fc00000".

Example:

// Java program to demonstrate the example 
// of floatToIntBits (float value)
// method of Float class

public class FloatToIntBitsOfFloatClass {
    public static void main(String[] args) {
        // Variables initialization
        float value1 = 18.20f;
        float value2 = 19.20f;

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

        // It returns the bits denoted by the single 
        // precision floating-point argument by calling 
        // Float.floatToIntBits(value1)
        int result1 = Float.floatToIntBits(value1);

        // It returns the bits denoted by the single 
        // precision floating-point argument by calling 
        // Float.floatToIntBits(value2)
        int result2 = Float.floatToIntBits(value2);

        // Display result1,result2 values
        System.out.println("Float.floatToIntBits(value1): " + result1);
        System.out.println("Float.floatToIntBits(value2): " + result2);
    }
}

Output

value1: 18.2
value2: 19.2
Float.floatToIntBits(value1): 1100061082
Float.floatToIntBits(value2): 1100585370






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.