int occupies 4 bytes in a 32-bit computer, primarily to figure out the order in which the 4 bytes are stored in memory.
1#include <iostream>2 3 using namespacestd;4 5typedefstructInt_char6 {7 intA;8UnsignedChar*b;9 };Ten One intMain () A { - Int_char A; - inti; the //test int; -A.a=0X01AB02CD; -a.b= (unsignedChar*) &a.a; - for(i=0;i<4; i++) +printf"%02x\n", * (a.b+i)); -cout<<""<<Endl; + //test short; A ShortC=0x01ab; ata.b= (unsignedChar*) &C; - for(i=0;i<2; i++) -printf"%02x\n", * (a.b+i)); - - GetChar (); - return 0; in}
The output is:
Cd
02
Ab
01
Ab
01
Thus, int,short are low-byte low address, high-byte existence high address;
How the 16-bit and 32-bit numbers are stored?——
"Http://see.xidian.edu.cn/cpp/html/1615.html"
In this link, there are now only two of the 32-digit storage: low-priority (Little-endian) and High-priority (Big-endian).
Which mode of storage is determined by the CPU, most computers store 32-bit numbers in high priority, but Intel CPU-based computers store 32-bit numbers in low-priority order .
My computer is using the CPU is Intel, which also confirms my previous results, first store the low byte to high byte in this order, that is, low byte existence low address, high byte existence high address .
Extended:
- Memory is so arranged that it can also be understood that when casting with type, the memory reads, such as int is cast to short, then short takes only two low bytes in int.
- How do you store "bits" in one byte of memory?
--------------------------------------------------------------------------------
New questions:
0xAB is according to our normal thinking 1010 1011 storage, or 1101 0101 so in turn to store?