For unsigned numbers, it is relatively simple and can be calculated directly according to the number of digits occupied:
Unsigned short integer 16 bits? 0~2 power of 16-1 (i.e. 65535)
Unsigned int 16 bit? 0~2 power of 16-1 (i.e. 65535)
Unsigned long integer? 32? 0~2 to the 32nd power-1 (i.e. 4294967295)
For signed numbers, because the sign bit occupies one bit, negative numbers should be represented by complement.
Take 8-bit data as an example: binary1111means-1, 1000000 means -65438. Binary 0000000000 means 0,01111means 127, so the range of positive numbers is 0~ 127. Together, it is-128~ 127. If you look for the law and find that it is the (8- 1) power of -2 to the (8- 1) power of 2, then you can get any range of numbers:
Short 16 bit? -2' s (16- 1) power ~2' s (16- 1) power-1 (that is, -32768~32767).
Int 16 bit? -2' s (16- 1) power ~2' s (16- 1) power-1 (that is, -32768~32767).
Dragon? 32? -2 to the power of (32- 1) ~2 to the power of (32- 1)-1 (i.e.-2147483648 ~ 2147483648).
Extended data:
(1)char: Character data, which belongs to integer data and occupies one byte.
(2)unsigned char: unsigned character data, which is a kind of integer data and occupies one byte.
(3)short: short integer data, which belongs to one kind of integer data and occupies two bytes.
(4) Unsigned short integer: unsigned short integer data, which belongs to a kind of plastic data and occupies two bytes.
(5)int: plastic data, which belongs to a kind of integer data and occupies four bytes.
(6)unsigned int: unsigned integer data, which belongs to one kind of integer data and occupies four bytes.
(7)long: Long integer data, which belongs to one kind of integer data and occupies four bytes.
(8) Unsigned long integer: unsigned long integer data, which belongs to a kind of plastic data and occupies four bytes.
There are two types of real variables, floating point and double precision. The following table lists the number of memory bits occupied by these two types and their apparent ranges. Number of bits occupied by data type:
Floating 32 3.4e-038~3.4e+038
Double 641.7e-308 ~1.7e+308
Double-precision float has higher precision and larger apparent range than common single-precision float.
References:
Integer data _ Baidu Encyclopedia