【问题标题】:How big can a 64bit signed integer be?64 位有符号整数可以有多大?
【发布时间】:2011-05-14 17:16:46
【问题描述】:

redis

支持的值范围 HINCRBY 仅限于 64 位有符号 整数。

我想知道这个 64 位有符号整数能有多大。

【问题讨论】:

    标签: integer 64-bit


    【解决方案1】:

    这篇文章很适合了解更多关于这个主题的信息:http://en.wikipedia.org/wiki/Integer_(computer_science)

    所以问题的答案应该是: 从 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807, 或从 -(2^63) 到 2^63 - 1

    存储在有符号整数中的最大正数表示为二进制

    ----- 63 个 -----

    0111111111111111111111111111111111111111111111111111111111111111
    

    如果你仔细想想,你会发现这个数字正好是 2^63 - 1。

    【讨论】:

    • 另外,查看维基百科页面:9223372036854775807
    • 喜欢你的 63 条评论,即将计数 :)
    • @user1767754 不要审查基于 cmets 的代码。 ;)
    • 或者,在一个容易说话的版本中:九 quintillion 223 万亿 372 万亿 3685404 775807 :-)
    【解决方案2】:

    有符号整数的大小范围为 -2^(n-1) 到 2^(n-1) - 1,因此在这种情况下,最大值为 2 ^ 63 - 1 或 9,223,372,036,854,775,807

    【讨论】:

      【解决方案3】:
          Formula   
      
          2^(n-1) is the formula of the maximum value of a Bigint data type.
      
          In the preceding formula N is the size of the data type. The ^ operator calculates the power of the value.
      
          Now determine the value of N in Bit:
      
      Select (max_length * 8) as 'Bit(s)' from sys.types Where name = 'BIGInt'
      =64 Bits
      

      范围::-9223372036854775808 到 9223372036854775807

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-11
        • 1970-01-01
        • 2018-11-05
        • 2013-07-08
        • 2011-04-12
        • 1970-01-01
        • 2023-03-18
        • 1970-01-01
        相关资源
        最近更新 更多