The value range of TINYINT in mysql, and that of mysqltinyint
In MySQL, the value range of Tinyint is-128 to 127. The unsigned range is 0 to 255 (see the official MySQL 5.1 reference manual http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#numeric-types ).
Tinyint occupies 1 byte of storage space, that is, 8 bits ). So how does Tinyint value range come from? Let's first look at the unsigned situation. The unsigned minimum value means that all eight bits are 0, and the value is 0 in decimal format. Therefore, the minimum value of the unsigned Tinyint is 0. the maximum unsigned value means that all 8 bits are 255, which is in decimal format. this is easy to understand.
How does a signed Tinyint value range come from? In a computer, the highest bit is used as the symbol. 0 indicates positive, 1 indicates negative, and the rest indicates numerical values. The minimum value of a signed 8-bit is
1 1 1 1 1 1 1 1 1 =-127
Negative value
Maximum value:
0 1 1 1 1 1 1 1 = + 127
Positive Value
How can the minimum signed value be-127 instead of-128? This is the key point of this article. In the computer, the negative value is supplemented
Why is the minimum value of a signed TINYINT-128? Although "-0" is also "0", the "-0" complement code is different from "+ 0" according to the positive, reverse, and complement system, in this case, two supplementary codes represent a value. In order to match the complement code with numbers one by one, "0" is always represented by "+ 0. At the same time, in order to make full use of resources, the original "-0" complement code should be set to represent-128.
Mysql unsigned tinyint can store up to many Integers
In MySQL, the value range of Tinyint is-128 to 127. The unsigned range is 0 to 255.
Tinyint occupies 1 byte of storage space, that is, 8 bits ). So how does Tinyint value range come from? Let's first look at the unsigned situation. The unsigned minimum value means that all eight bits are 0, and the value is 0 in decimal format. Therefore, the minimum value of the unsigned Tinyint is 0. the maximum unsigned value means that all 8 bits are 255, which is in decimal format.
Why is the minimum value of a signed TINYINT-128? Although "-0" is also "0", the "-0" complement code is different from "+ 0" according to the positive, reverse, and complement system, in this case, two supplementary codes represent a value. In order to match the complement code with numbers one by one, "0" is always represented by "+ 0. At the same time, in order to make full use of resources, the original "-0" complement code should be set to represent-128
Mysql Data Type tinyint
This should be controlled in the code. It cannot be displayed if it is directly queried in the database. Use the code to process the query results.