Java Basic Data Type

Source: Internet
Author: User
Basic Type Size Minimum value Maximum Value
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-bit Ieee754 Ieee754
Double 64-bit Ieee754 Ieee754
Void      

Note! : The ^ In the table represents the power ~

Use the float class to save development time
Author: builder.com
AM
 

Even if you know the IEEE floating point number, you may have never processed this type of data in bits. Next I will show you how to process IEEE floating point numbers one by one in bits. Next time when your Java project needs to create floating point numbers from the bit sequence or the floating point to create a bit sequence, you will know that the float class can complete this job.

IEEE floating point number

The IEEE 754 floating point single-precision numeric format defines a bit layout for storing floating point numbers. In the blank bit layout, one bit is reserved as the symbol bit, eight bits are reserved as the index, and 23 bits are reserved as the ending number. These bits are arranged from the most important to the least important, as shown in the following example:

 
 
31 0
|
Seeeeeeeemmmmmmmmmmmmmmmmmmmmm

Where:

S = symbol bit
E = index
M = tail

You can purchase a full IEEE floating point number explanation from the IEEE site. (If you search for IEEE 754 online, you can find the free version .)

Float's contribution to the Java Community

The following example program uses two float methods to convert a floating point number to a bit, and then converts the bit to a floating point number.

The float. floattointbits (float f) method can be used to convert a floating point number into a bit sequence. This method returns a 32-bit integer representing the IEEE 754-bit arrangement of the floating point you provide as the parameter.

The float. intbitstofloat (INT bits) method can be used for reverse conversion. This method accepts the passed integers as parameters and converts these bits into an IEEE floating point number.

The following is an example program:

Public class bitstip {
Public static void main (string ARGs []) {
Float F = float. parsefloat (ARGs [0]);
Int bits = float. floattointbits (f );

System. Out. println ("bits:" + bits );
System. Out. println ("back to float:" + float. intbitstofloat (BITs ));
}
}

If you have to manually perform this conversion, you will appreciate the two simple methods for saving your work. If you are processing 64-bit data, you can use the double Wrapper class. This class provides the same method for handling IEEE 754 double-precision floating point numbers.

You 'd better read about Javadoc and check the conversion between floating point numbers and bit sequences so that you can fully understand what these methods can do for you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.