Single-precision floating point number in memory format in VC ++ 6.0

xiaoxiao2021-03-06  26

#include int main () {float a = 2; / * Here, A is equal to 2, -2, 4, 6, 1, 0.75, 2.5, 0.1, 0 * / char * p = (char) *) & a; p = 3; / * Put the address from high to low * / int line = 0, TEMP = 0; while (Temp <4) {for (int i = 7; i> = 0; I -) {IF (* p & (1 << i)) cout << '1'; / * For operation, if and 1 and is 1, this binary is 1, otherwise 0, where the left shift operation makes 1 continuous High moving * / else cout << '0'; line ; if (line% 4 == 0) cout << '';} TEMP ;

P -;} cout << endl; return 0;

Test results and results description give the explanation on MSDN Library (English original, original smell):

The Format, Then, for The Various Sizes IS FOLLOWS:

FormatBYTE 1BYTE 2BYTE 3BYTE 4 ... BYTE nreal * 4XXXX XXXXXMMM MMMMMMMM MMMMMMMM MMMM real * 8SXXX XXXXXXXX MMMMMMMM MMMMMMMM MMMM ... MMMM MMMMreal * 10SXXX XXXXXXXX XXXX1MMM MMMMMMMM MMMM ... MMMM MMMM

Note: The research is 4-byte floating point numbers, namely FLOAT type.

Signa Bits. Note That The Leftmost Bits. Note That The Leftmost Bit Is Assumed in Real * 4 And Real * 8 Formats, But Is Present As "1" in Byte 3 of The Real * 10 Format.

To Shift The Binary Point Propries.

Examples

The Following Area Some Examples in Real * 4 Format:

In The Following Example, The Sign Bit Is Zero, And The Stored Exponent IS 128, OR 100 0000 0 in Binary, Which IS 127 Plus 1. The Stored Mantissa IS (1.) 000 0000 ... 0000 000, Which Has An Implied Leading 1 and Binary Point, So The Actual Mantissa Is One. SXXX XXXX XMMM MMMM ... mmmm mmmm

2 = 1 * 2 ** 1 = 0100 0000 0000 0000 ... 0000 0000 = 4000 0000 Same as 2 Excepter That The Sign Bit IS set. This is true for all IEEE Format floating-point numbers. -2 = -1 * 2 ** 1 = 1100 0000 00 00 00 ... 0000 0000 = C000 0000 Same Mantissa, Exponent Increases by One (Biased Value IS 129, OR 100 0000 1 in binary. 4 = 1 * 2 ** 2 = 0100 0000 1000 0000 ... 0000 0000 = 4080 0000 Same Exponent, Mantissa Is Larger By Half - It's (1.) 100 0000 ... 0000 0000, Which, Since this is a binary fraction, IS 1 1/2 (The Values ​​of Thae Fractional Digits Are 1/2, 1/4, 1/8, and So forth). 6 = 1.5 * 2 ** 2 = 0100 0000 1100 0000 ... 0000 0000 = 40c0 0000 Same Exponent As Other Powers of Two, Mantissa Is One Less Than TWO AT 127, OR 011 1111 1 in binary. 1 = 1 * 2 ** 0 = 0011 1111 1000 0000 ... 0000 0000 = 3F80 0000 The BiaSed Exponent IS 126, 011 1111 0 in binary, and the Mantissa IS (1.) 100 0000 ... 0000 0000, Which IS 1 1/2. .75 = 1.5 * 2 ** - 1 = 0011 1111 0100 0000 ... 0000 0000 = 3F40 0000 Exact Ly the Same As Two Except this the bit that represents 1/4 is set in the mantissa. 2.5 = 1.25 * 2 ** 1 = 0100 0000 0010 0000 ... 0000 0000 = 4020 0000 1/10 is a refeating fire in binary ............................................................................ Means That The Factor by Which To Multiply IS 2 ** - 4 =

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

New Post(0)