In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of data storage in C language, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.
(1) the big end and the small end hide the clue 1.1 what is the big end and the small end
Big-end (storage) mode means that the low bit of data is stored in the high address of memory, while the high bit of data is stored in the low address of memory.
The small end (storage) mode means that the low order of the data is stored in the low address of the memory, while the high bit of the data is stored in the high address of the memory.
1.2 large end and small end mode 1) large end mode:
Low address-> high address
0x0A | 0x0B | 0x0C | 0x0D
2) small end mode:
Low address-> high address
0x0D | 0x0C | 0x0B | 0x0A
1.3 Why are there big ends and small ends?
Why is there a difference between big and small end patterns?
This is because in the computer system, we are in bytes, each address unit corresponds to a byte, a byte is 8bit.
However, in C language, in addition to 8bit's char, there are also 16bit's long type and 32bit's long type (depending on the specific compiler). In addition, for processors with bits greater than 8 bits, such as 16-bit or 32-bit processors, because the register width is greater than one byte, there must be a problem if multiple bytes are arranged. This leads to large-end storage mode and small-end storage mode.
For example:
A short type x of 16bit, the address in memory is 0x0010 and the value of 0x1122 is 0x1122, then 0x11 is high byte and 0x22 is low byte. For large-end mode, put 0x11 in the low address, that is, 0x0010, and 0x22 in the high address, that is, 0x0011. Small
End mode, just the opposite. Our commonly used X86 architecture is small-end mode, while KEIL C51 is large-end mode. Many ARM,DSP are in small-end mode. Some ARM processors can also be chosen by the hardware to be in large-end mode or small-end mode.
1.4 how to determine the byte order of a machine
It is usually tested through union. The following code can be used to test whether your compiler is in large-end mode or small-end mode:
The space occupied by union data is equal to the space occupied by its largest member.
Access to members of the union type starts at an offset of 0 from the base address of the consortium, that is, access to any variable of the federation starts from the first address of the union.
A federation is a data type that stores different types of data in the same storage space. The addresses of these storage areas are all the same, the memory of different storage areas in the federation is overlapping, and any other changes will be affected. Then you can test the size end by forcing the type conversion to determine the actual storage location:
(2) floating-point storage in memory
Common floating point numbers:
3.14159 1E10
Floating point family includes: float, double, long double type.
Range represented by floating-point numbers: defined in float.h
Examples of floating point storage:
What is the result of the output?
Num and * pFloat are obviously the same number in memory, why are floating-point numbers and integers so different in interpretation?
To understand this result, it is important to understand the representation of floating-point numbers inside the computer.
2.1 Storage of floating point numbers in memory
According to the international standard IEEE (Institute of Electrical and Electronic Engineering) 754, any binary floating point number V can be expressed in the following form:
For example:
Decimal 5. 0, written in binary, is 101.0, which is equivalent to 1.01 × 2 ^ 2. Then, according to the format of V above, we can get the slog0Magnum Manners 1.01Magi Edition2.
The decimal system is-5.0. written in binary, it is-101.0, which is equivalent to-1.01 × 2 ^ 2. So, sails 1, Manners, 1. 01, girls, 2.
IEEE 754 stipulates that:
For 32-bit floating-point numbers, the highest 1 bit is the symbol bit s, the next 8 bits are exponent E, and the remaining 23 bits are significant digits M.
For 64-bit floating-point numbers, the highest 1 bit is the symbol bit S, the next 11 bits are exponent E, and the remaining 52 bits are significant digits M.
IEEE 754 also has some special provisions for the significant number M and the index E.
As I said earlier, 1 ≤ M
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.