How big can a 64bit signed integer be?

江枫思渺然 提交于 2019-12-20 11:05:57

问题


In redis,

The range of values supported by HINCRBY is limited to 64 bit signed integers.

And I'd like to know how big can that 64 bit signed integer be.


回答1:


This article is good for more information about this topic: http://en.wikipedia.org/wiki/Integer_(computer_science)

So the answer to the question should be: From -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, or from −(2^63) to 2^63 − 1

The highest positive number stored in a signed int is represented binary as

----- 63 ones -----

0111111111111111111111111111111111111111111111111111111111111111

If you think carefully you can find out that this number is exactly 2^63 - 1.




回答2:


A signed integer ranges from size −2^(n−1) through 2^(n−1) − 1 so in this case the maximum value would be 2 ^ 63 - 1 or 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

Range:: -9223372036854775808 to 9223372036854775807



来源:https://stackoverflow.com/questions/6003492/how-big-can-a-64bit-signed-integer-be

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!