Char type: it accounts for 1B on 32-bit machines and 1B on 64-bit machines;
Note: The char type is named after a single character in a text string. Therefore, both 32 machines and 64 machines occupy one byte.
Value Range: 0 ~ 255;
Cause: Because the char type occupies 1B while the 1B type has 8 bits, the value range is: 00000000 ~ 11111111 (that is, 0 ~ 255)
For integer types, short must be at least 16 bits and long must be at least 32 bits. The compiler designer determines whether the default int is 16-bit, 32-bit, or other values. However
Note: The length of the int type cannot exceed the length of the long type. Generally, the default value of this choice is the most natural (efficient) number of digits for this machine.
Int type: 4B for 32-bit machines and 4B for 64-bit machines;
Value Range: Unsigned int (unsigned INT): 0 ~ 4294672295 (2 ^ 32 );
Signed (INT):-2147483648 ~ 2147483647 (2 ^ 31)
Cause: Because int type occupies 4B, and 4B HAS 32bit, the value range is: 0 ~ 2 ^ 32, the same as the unsigned type.
Short int type: 2b for 32-bit machines and 2B for 64-bit machines;
Value Range: Unsigned short (0 ~ 65535 (2 ^ 16 );
Signed (short):-32768 ~ 32767 (2 ^ 15)
Cause: Because the short int type occupies 2B, and 2B has 16 bits, the value range is: 0 ~ 2 ^ 16. The same is true for the unsigned type.
Long int type: 4B for 32-bit machines and 8B for 64-bit machines;
Value Range: 0 to unsigned long on 32-bit machines ~ 4294672296 (2 ^ 32 );
Signed (long):-2147483648 ~ 2147483647 (2 ^ 31)
On 64-bit machines: Unsigned long 0 ~ 2 ^ 64;
Signed (long): 2 ^ 63 ~ 2 ^ 63-1
Cause: on 32-bit machines, because the long int type occupies 4B, and 4B HAS 32bit, the value range is: 0 ~ 2 ^ 32, the same as the unsigned type.
On 64-bit machines, because the long int type occupies 8B, and 8B has 64bit, the value range is: 0 ~ 2 ^ 64, the same as the unsigned type.
Since all the above data types represent integers, the processing process is the same. For floating-point data, computers do not process integers.
Therefore, floating point data should be discussed separately.
Currently, most computer systems use IEEE floating point representation. So let's take a brief look at the IEEE floating point representation.
IEEE floating point standard represents a number in the form of V = (-1) ^ s * m * 2 ^ E:
Sign (sign): S determines whether the number is negative (S = 1) or positive (S = 0), and the symbol bit of the value 0 is interpreted as a special processing;
Sifnficand: M is a binary decimal, and its range is 1 ~ 2-ε, or 0 ~ 1-ε;
Level Code (exponent): E is used to weight floating point numbers. This weight is the power of E (which may be a negative number) of 2 ).
Divide the bit representation of a floating point number into three fields and encode these values respectively:
1. A separate symbol bit s directly encodes the symbol S;
2. K-bit code segment exp encoding level code E;
3. The N-digit decimal field frac encodes m, but the encoded value depends on whether the value of the level code segment is equal to 0;
In the C language: In the float format, the S, exp, and Frac fields are 1-bit, K = 8-bit, and n = 23-bit, respectively, and a 32-bit representation is obtained.
In double-precision floating-point format, the S, exp, and Frac fields are 1-bit, K = 11-bit, and n = 52-bit, respectively, and a 32-bit representation is obtained.
Therefore, if positioning is indicated, the encoded value can be divided into three different cases based on the exp value:
1. normalized value: This is the most common situation. When the bits of EXP are not all 0 (the value is 0), and not all are 1 (the single precision value is 255, and the double precision value is 2047,
This is the case. In this case, the level code segment is interpreted as a signed integer in the form of offset. That is to say, the order code value is E = e-bias, where E is not
Number of symbols, its bit is represented as ek-1... E1e0 (Note: I is subscript), while bias is an offset value equal to 2 ^ (k-1)-1 (single precision is 127, double precision is 1023.
The value range of the resulting index is:
For single precision:-126 ~ + 127; (00000001-127 ~ 11111110-127)
For dual precision:-1022 ~ + 1023 (00000000001-1023 ~ 11111111110-1023)
Note: Because the exp bit mode cannot be both 0 and 1, E ranges from 00000001 ~ 11111110
For double precision, the E range is 00000000001 ~ 11111111110;
The description of the fractional field Frac is a small value F, where 0 <= F <1, and its binary value is 0.f( N-1 )... F1f0 (n is the subscript), that is, the highest valid digit of the binary decimal point
To the left. The ending number is defined as M = 1 + F.
2. Non-normalized value: When the level code field is all 0, the number is not normalized. In this case, the order code value is E = 1-bias, and the end value is M = F, that is, a small number.
Segment value.
3. Special Value: There is no doubt that only the level code is 1. When the number of small number fields is all 0, the resulting value indicates infinite. When S = 0, it indicates positive infinity. When S = 1, it indicates negative infinity.
Float Type: 4B for 32-bit machines and 4B for 64-bit machines;
Value range:
For normalized values:-2 ^ (127) * (1 + 2 ^ (-1) + 2 ^ (-2) + ...... + 2 ^ (-23 ))~ 2 ^ 127*(1 + 2 ^ (-1) + 2 ^ (-2) + ...... + 2 ^ (-23 ));
For non-normalized values:-2 ^ (-126) * (2 ^ (-1) + 2 ^ (-2) + ...... + 2 ^ (-23 ))~ 2 ^ (-126) * (2 ^ (-1) + 2 ^ (-2) + ...... + 2 ^ (-23 ));
Double Type: 8B on 32-bit machines and 8B on 64-bit machines;
Value range:
For normalized values:-2 ^ (1023) * (1 + 2 ^ (-1) + 2 ^ (-2) + ...... + 2 ^ (-52 ))~ 2 ^ 1023*(1 + 2 ^ (-1) + 2 ^ (-2) + ...... + 2 ^ (-52 ));
For non-normalized values:-2 ^ (-1023) * (2 ^ (-1) + 2 ^ (-2) + ...... + 2 ^ (-52 ))~ 2 ^ (-1023) * (2 ^ (-1) + 2 ^ (-2) + ...... + 2 ^ (-52 ));
Here, we will mention the bool type. Note: The bool type is only available in C ++, And the bool type is not defined in C;
Bool type: it accounts for 1B on 32-bit machines, and also for 1B on 64-bit machines. In C ++, 0 is false, and non-0 is true. In fact, the bool type does not really occupy 1 byte,
It only occupies 1 bit.
The following example shows that:
# Include <stdio. h> int main (void) {bool flag = true; int num = 255; // The binary value of 255 is 11111111 if (Num & flag) = 1) {printf ("flag only the position of end is not zero! \ N ") ;}return 0 ;}
Of course, there is no doubt that the result is: flag only the position of end is not zero!