about storage problems in memory for multi-byte data types
////////////////////////////////////////////////////////////////
int, short each is 4, 2 bytes. The way they are stored in memory is described below for a sample example.
int data = 0XF4F3F2F1;
Low-level storage of small memory units, high-height storage memory Unit
For example, the following:
Address: 0x80000x80010x80020x8003
Data:F1F2 F3F4//Above is a small-end mode and a big-endian storage mode////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// processing of floating-point numbers according to IEEE standards established in 1985
Single-precision floating-point numbers are 4 bytes, containing 1-bit sign bits s (integers 0, negative numbers 1), and 8-bit exponential bits e. 23-bit valid bit F
The floating-point type uses the scientific notation, for example, a decimal 12345 can be represented as 1.2345 * 10^4 (representing a power of 10 4)
Represented as 1.1000000111001 * 2^13 in binary notation
So a floating-point number in the computer indicates that the decimal 12345 should be this, the S bit is 0, because it is a positive number. The digits are 13+127=140 (127 is a single-precision floating-point number offset value, in order to indicate that there are only a few decimal parts). Valid bit is 1000000111001
When calculating, use ( -1) ^s * 1.f * 2^ (e-127), the result is 1* 1.1000000111001 * 2^ (140-127=13). Just like we said.
Also, for example, decimal decimal 0.125 converts to binary decimal 0.001 to be represented as 1* 1.0 * 2^ (124-127=-3)
Double, dual-precision floating-point numbers have 1-bit sign bits, 11-bit exponent bits, and 52-bit active numbers
Know the formula
N= ( -1) ^s*m*2^e
e=| E|-bias
Bias = 2^ (k-1)-1 (k is the number of digits of e)
m=|1.m|
Knowing that 12345 in-memory 10 binary representation later
0x4640e400 = 0 (0110 0) <100 0000 1110 0100 0000>
The numbers in parentheses are | e| = 140 so e=140-127=13
The numbers in the angle brackets are m=|1.m|=|1.100000011100100|=1.506958008.
Ok
Substituting formula n = ( -1) ^0*1.506958008*2^13=12345
How floating-point numbers are stored in memory in the C language