一个64位有符号整数能有多大?

46

redis中,

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

我想知道这个64位有符号整数最大可以是多少。

3个回答

87

这篇文章可以提供有关该主题的更多信息: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。

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

----- 63个1 -----

0111111111111111111111111111111111111111111111111111111111111111

如果你仔细思考,就会发现这个数字正好是2的63次方减1。


3
请查看维基百科页面:9223372036854775807 - Garrett
1
就像你的63个评论一样,我也快要数过来了 :) - user1767754
@user1767754 不要根据注释来审查代码。 ;) - user900360
4
或者用口语化的说法:九百二十三万亿三千七百二十三万零三十六亿八千五百四十七万七千八百零七 :-) - Ted
9.2艾克斯字节。http://highscalability.com/blog/2012/9/11/how-big-is-a-petabyte-exabyte-zettabyte-or-a-yottabyte.html - SteveS

9

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


1
    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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接