gpt4 book ai didi

mysql - 在 mysql 中表示 n 位无符号整数

转载 作者:行者123 更新时间:2023-11-29 01:32:47 31 4
gpt4 key购买 nike

我如何在 mysql 中表示这些数据?

16 bit unsigned integer -----Range: 0x0000 - 0xFFF7
64 bit unsigned int. Depicted as xx:xx:xx:xx:xx:xx:xx:xx -----Range: 0x0000 - 0xFFFFFFFFFFFFFFFF
2 bits ----- 00 - None, 01 - Residential Security, 10 - High Security
32 bit unsigned int

我是否应该将所有内容都转换为字符串并在应用层进行转换?

最佳答案

根据 MySQL's Overview of Numeric Types :

  • UNSIGNED SMALLINT:范围是 0 到 65535。这对于 16 位无符号整数就足够了。
  • UNSIGNED TINYINT:范围是 0 到 255。足够用于 2 位无符号整数。看来您需要保留前导零,因此也请使用 ZEROFILL。要将值保持为仅两个字符宽,您可以指定 UNSIGNED ZEROFILL TINYINT(2)
  • UNSIGNED INT:范围是 0 到 4294967295。足够用于 32 位无符号整数。
  • UNSIGNED BIGINT:范围是 0 到 18446744073709551615。见下文:

最后一个,64 位 unsigned int,有几个注意事项,来自上面的链接页面:

  • All arithmetic is done using signed BIGINT or DOUBLE values, so you should not use unsigned big integers larger than 9223372036854775807 (63 bits) except with bit functions! If you do that, some of the last digits in the result may be wrong because of rounding errors when converting a BIGINT value to a DOUBLE.
  • You can always store an exact integer value in a BIGINT column by storing it using a string. In this case, MySQL performs a string-to-number conversion that involves no intermediate double-precision representation.
  • The -, +, and * operators use BIGINT arithmetic when both operands are integer values. This means that if you multiply two big integers (or results from functions that return integers), you may get unexpected results when the result is larger than 9223372036854775807.

关于mysql - 在 mysql 中表示 n 位无符号整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6460509/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com