Big end, Small End
Big-end format: in this format, the high bytes of word data are stored in the low address, while the low bytes of word data are stored in the high address. The small-end format is the opposite of the big-end storage format, in the small-end storage format, the low address stores the low byte of word data, and the high address stores the high byte of word data.
Next, if someone else gives you a question, you can write a simple program to test whether the current system is large-end storage or small-end storage. How can we solve this problem.
Here we can consider using two methods: Using pointers and using union Consortium;
First, we need to know the characteristics of union:
1. Multiple members can be defined in union. The size of union is determined by the maximum size of members.
2. union Members share the memory of the same block. Only one member can be used at a time.
3. assigning values to a member will overwrite the values of other members.
Let's look at a simple code:
union UN { char c; int i; }un;
In fact, the system allocates an int-sized space for us to store our Defined Characters c and I. The storage method is as follows:
We can see that c and I are a public space. Therefore, at the same time, we can only ensure that a variable member is used at a certain time.
The following are two small programs used to test whether the current system is large-end or small-end storage:
Method 1: Use Pointer features
# Include <stdio. h> # include <windows. h> int check_sys () {int a = 1; char * p = (char *) & a; if (* p = 1) return 0; else return 1 ;} int main () {int ret = 0; ret = check_sys (); if (ret = 0) printf ("little"); else printf ("big "); system ("pause"); return 0;} Method 2: Use the unionint check_sys () {union UN {char c; int I;} un; un. I = 1; if (un. c = 1) return 0; else return 1;} int main () {int ret = 0; ret = check_sys (); if (ret = 0) printf ("little"); else printf ("big"); system ("pause"); return 0 ;}