Java double data Save in memory

Source: Internet
Author: User

Floating point numbers are saved in the following byte format:

Address +0 +1 +2 +3
Content seee eeee emmm MMMM MMMM MMMM MMMM MMMM

Over here
S represents sign bit, 1 is negative, 0 is positive
The power of the E offset 127, the binary Order code = (EEEEEEEE)-127.
The 24-bit mantissa is stored in 23-bit, storing only 23 bits, and the highest bit is fixed to 1. This method uses the least number of digits to implement the
The higher the significant number of digits, the better the precision.

0 is a specific value, the power is 0 The mantissa is also 0.

The floating-point number-12.5 is saved as a hexadecimal number 0xc1480000 in the store, and this value is as follows:
Address +0 +1 +2 +3
Content 0xc1 0x48 0x00 0x00

The conversion between floating-point numbers and hexadecimal equivalent save values is fairly straightforward. The following example shows the value above-12.5 how to turn
Change.
The floating-point save value is not a direct format, and to convert to a floating-point number, the bit must save the format table by the floating-point number above
Separated by the list, for example:

Address +0 +1 +2 +3
Format seee eeee emmm MMMM MMMM MMMM MMMM MMMM
Binary 11000001 01001000 00000000 00000000
Hex C1 48 00 00

From this example you can get the following information:
The sign bit is 1 to indicate a negative number
Power is binary 10000010 or decimal 130,130 minus 127 is 3, which is the actual power.
The mantissa is the rear binary number 10010000000000000000000.


On the left side of the mantissa there is an elliptical decimal point and 1, which is often omitted in the save of the floating-point number, plus a 1 and a decimal
Point to the beginning of the mantissa, get the tail value as follows:
1.10010000000000000000000

Then, adjust the mantissa according to the index. A negative exponent moves the decimal point to the left. A positive exponent moves the decimal point to the right. because
The index is 3 and the mantissa is adjusted as follows:
1100.10000000000000000000

The result is a binary floating-point number, and the binary on the left of the decimal point represents the power of 2 of the position, for example: 1100 means
(1*2^3) + (1*2^2) + (0*2^1) + (0*2^0) = 12.
The right of the decimal point also represents the power of 2 of the position, but the power is negative. For example:. 100. Expression (1*2^ (-1)) +
(0*2^ (-2)) + (0*2^ (-2)) ... =0.5.
The number of these values is 12.5. Because the set symbol bit indicates that the number is negative, the hexadecimal value 0xc1480000 represents-
12.5.

Http://topic.csdn.net/u/20080830/21/e5c68e0b-b751-49e8-895c-05fac5e0580e.html

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.