Java basic data type

xiaoxiao2021-03-06  18

Basic model size minimum maximum Boolean -------------- Char 16-bit unicode 0 Unicode 2 ^ 16-1 BYTE 8-BIT-128 127 Short 16-bit - 2 ^ 15 2 ^ 15-1 INT 32-bit-2 ^ 31 2 ^ 31-1 long 64-bit-2 ^ 63 2 ^ 63-1 FLOAT 32-BITIEEE754IEEE754 Double 64-Bitiee754ieee754 Void

note! : The representative of the table is secondary.

Use Float class save development time of: Builder.com 2004-11-16 11:50 AM

Even if you might know the number of IEEE floats, you may never have this type of data in a specific bit. Below I will show you how to handle the IEEE floating point by one, next time you create a floating point number from the bit sequence, or when you create a bit sequence from the floating point number, you know that the float class can be completed. jobs.

IEEE floating point number introduction

The IEEE 754 floating point single precision digital format defines a bit layout for storing floating point numbers. In the air bits layout, a bit of a bit is a symbolic bit, eight than the special index, 23 ratios are missing the mantissa. These bits are arranged in the most important bit to the least important bits, as shown in the following example:

31 0 | | seeeeeeeemmmmmmmmmmmmmmmmmmmmm

among them:

S = symbol bit E = index m = mantissa

You can purchase a complete explanation of the IEEE floating point number from the IEEE site. (If you search for IEEE 754 online, you should be able to find a free version.)

Float Contribution to the Java Community

The following sample program uses Float's two ways to turn a floating point number into bits, then convert these bits into a floating point number.

A floating point number can be converted to a bit sequence using the float.floattointbits (float f) method. This method returns a 32-bit integer that represents the IEEE 754 bit arrangement of floating point numbers as parameters.

Use the float.intBitStofloat (int BITS) method to reverse direction conversion. This method accepts the incoming integer as a parameter, converting these bits into an IEEE floating point number.

Below is an example program:

Public class bitstip {public static void main (string args []) {float f = float.parsefloat (args [0]); int bits = float.floatthannelBits (f);

System.out.println ("BITS:" BITS); System.Out.println ("Back to Float:" Float.intBitstofloat (Bits));}}

If you have to handle this conversion, then you will appreciate these two simple ways to save you. If you are processing 64 digits, you can choose to use the Double Package (Wrapper) class. This class provides the same method to handle IEEE 754 double precision floating point.

It is best to choose to read Javadoc, see the part of the conversion between floats and bit sequences, to completely understand what these methods can do for you.

转载请注明原文地址:https://www.9cbs.com/read-49920.html

New Post(0)