Into the basic data types 整数类型
and the 浮点类型
two categories. Wherein the integer type and can be subdivided into 有符号整型
the 无符号整型
.
1. integer type
Signed integer
- short int
- int
- long int
- long long int
- char (integer to store characters)
Unsigned int
- unsigned short int
- unsigned int
- unsigned long int
- unsigned long long int
- unsigned char (integer to store characters)
Wherein the latter type can not less than the foregoing type, i.e., short int
the space occupied may be equal to int
but not greater than it is, or long int
may be equal to or larger than the int
footprint. For example, 16-bit machine, int
and short int
accounted for 16, long int
accounting for 32-bit, 32-bit machine and int
also becomes a 32-bit, specifically the following table.
Integer | 16-bit compiler | 32-bit compiler | 64-bit compiler |
---|---|---|---|
char | 1 | 1 | 1 |
short int | 16 | 16 | 16 |
int | 16 | 32 | 32 |
long int | 32 | 32 | 64 |
long long int | 32 | 64 | 64 |
Under various compiler 32/64 integer in the range:
| ------ |: ------: |: ------: |
| integer | decimal range | corresponding to binary |
| Short int | [-32767, 32767] | 1/0 15. 1 |
| int | [-2147483647, 2147483647] | 31 is 1/0 th ||. 1
| Long int 32 | [-2147483647, 2147483647] | 31 is 1/0 th. 1 |
| Long int 64 | [-9,223,372,036,854,775,807, 9223372036854775807] | 1/0 63 Ge 1 |
| Long Long int | [-9,223,372,036,854,775,807, 9223372036854775807] | 1/0 63 Ge 1 |
| Short unsigned int | [0, 65535] | 16 Ge 1/0 1 |
| unsigned int | [0, 4294967295] | 1/0 32 th. 1 |
| Long unsigned int 32 | [0, 4294967295] | 1/0 32 th. 1 |
| Long unsigned int 64 | [0, 18446744073709551615] | 1/0 64 th 1 |
| Long Long unsigned int | [0, 18446744073709551615] | 1/0 64 th 1 |
Thus, the type of order is used short
- unsigned short
- int
- unsigned int
and so on. have to be aware of is,For (Now mainly 32/64 bit). For long
more than int
large systems, should be used int
to reduce the burden of runninglong
and int
the same system, use long
the type of support to ensure downward.
2. floating point type
Floating point type using a manner similar to scientific notation, to represent data includes a fractional including greater range, it can be divided float
, double
and long double
, IEEE floating-point standard with a special notation to represent a number n:
n = (-1)^{s} × m × 2^{e}
s
Sign i.e., to represent the number of positive and negative introduced, when s = 1 is negative, non-negative 0e
An index scale factor, called the floating point exponent
e = | E | - Bias
E
It represents the order code, binary,| E |
represents a decimal number corresponding to the binary number,Bias
the number bias
m = | 1.M |
M
It is a binary fraction, the second predetermined bit mantissa plus decimal pointm
, in the range [1, 2) or [0, 1)
In single precision float
, for example, the type occupies the space 32, wherein position 32 (N31) is the sign bit, N30-N23-bit to 8-bit exponent, N22-N0 bits of 23-bit mantissa bits.
For example, there is a float float n = 15213.0
converted to binary N = 11101101101101 = 1.1101101101101 × 2 ^ 13 ( left of the decimal point 13)
is 1.1101101101101 = 1.M
FRAC = 11011011011010000000000
E = 13 isAnd because Bias = 127
so | E | = 140
E = 10.0011 millionTherefore, floating-point representation:
0 10.0011 million 1011011011010000000000
So, how to solve the floating-point types of the range? The float 32 likewise as an example, can be introduced according to the above has:
n = (-1)^{s} × m × 2^{| E | - 127}
Maximum value when the following conditions
E
I.e. = 11111110| E |
= 2541.M
1.11111111111111111111111 = (1 1.23) i.e.m
= 2-2 ^ (- 23),
thusn
the maximum value is [2-2 ^ (- 23)] × 2 ^ 127 = 3.4028 × 10 ^ 38
The minimum value when the following conditions
E
I.e. = 00000001| E |
= 11.M
= 1.00000000000000000000001 i.e.,m
= 1 + 2 ^ (- 23),
thusn
the minimum value is [1 + 2 ^ (- 23 )] × 2 ^ (- 126) = 1.1755 × 10 ^ (- 38)
Thus obtained floating-point types of ranges:
| ------ |: ------: |: ------: |
| float | median | range |
| a float | 32 | [-3.4028 × 10 ^ 38 is , -1.1755 × 10 ^ (- 38 is)] ∪ [1.1755 × 10 ^ (- 38 is), ^ 38 is 3.4028 × 10] |
| Double | 64 | [-1.7977 × 10 ^ 308, -2.2250 × 10 ^ (- 308 )] ∪ [2.2250 × 10 ^ (- 308), 1.7977 × 10 ^ 308] |
* Learn more about the IEEE 754 available CSAPP chapter or consult this document