Http://indian.blog.163.com/blog/static/108815820056403180/
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 to this article, in the computer, the negative value is to use the complement code (positive code, back code, complement the concept of code see the http://indian.blog.163.com/blog/static/1088158200610942745817)
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.