MySQL中有符号和无符号的区别?

时间:2022-06-24 11:37:11

What is the difference between signed and unsigned in MySQL? And what does signed and unsigned mean?

MySQL中有符号和无符号有什么区别?签名和签名是什么意思?

3 个解决方案

#1


24  

Unsigned numbers do not have the minus sign. Unsigned number can be only positive or zero (e.g. 123, 0). Signed numbers can be also negative (e.g. -42).

无符号数字没有减号。无符号数只能是正数或零(例如123,0)。签名号码也可以是负数(例如-42)。

This answer explains the difference throughly.

这个答案彻底解释了差异。

#2


7  

The range that you can store in a given space. E.g., quoting from the docs:

您可以在给定空间中存储的范围。例如,引用文档:

 TINYINT[(M)] [UNSIGNED] [ZEROFILL]

A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

一个非常小的整数。有符号范围是-128到127.无符号范围是0到255。

and similarly of course for other larger integer types.

当然对于其他更大的整数类型也是如此。

#3


3  

Range of possible values, as seen on this table.

可能值的范围,如此表所示。

It's not specific to MySQL, it is a consequence of how integers are represented in a computer. Sign takes one bit for itself, thus the maximum number gets (roughly) halved. You can also think of it like shifting the whole thing by half the range downwards. (Also, because there's an even number of available numbers and there aren't two zeroes, you get one more negative number than positive). If you want to know more, read up on two's complement.

它不是特定于MySQL,它是如何在计算机中表示整数的结果。符号本身需要一位,因此最大数量(大致)减半。您也可以将其视为向下移动整个范围的一半。 (另外,因为有可用数量的偶数且没有两个零,所以你得到的数字比正数多一个)。如果你想了解更多,请阅读两个补码。

#1


24  

Unsigned numbers do not have the minus sign. Unsigned number can be only positive or zero (e.g. 123, 0). Signed numbers can be also negative (e.g. -42).

无符号数字没有减号。无符号数只能是正数或零(例如123,0)。签名号码也可以是负数(例如-42)。

This answer explains the difference throughly.

这个答案彻底解释了差异。

#2


7  

The range that you can store in a given space. E.g., quoting from the docs:

您可以在给定空间中存储的范围。例如,引用文档:

 TINYINT[(M)] [UNSIGNED] [ZEROFILL]

A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

一个非常小的整数。有符号范围是-128到127.无符号范围是0到255。

and similarly of course for other larger integer types.

当然对于其他更大的整数类型也是如此。

#3


3  

Range of possible values, as seen on this table.

可能值的范围,如此表所示。

It's not specific to MySQL, it is a consequence of how integers are represented in a computer. Sign takes one bit for itself, thus the maximum number gets (roughly) halved. You can also think of it like shifting the whole thing by half the range downwards. (Also, because there's an even number of available numbers and there aren't two zeroes, you get one more negative number than positive). If you want to know more, read up on two's complement.

它不是特定于MySQL,它是如何在计算机中表示整数的结果。符号本身需要一位,因此最大数量(大致)减半。您也可以将其视为向下移动整个范围的一半。 (另外,因为有可用数量的偶数且没有两个零,所以你得到的数字比正数多一个)。如果你想了解更多,请阅读两个补码。