在python中获取64位整数
所以我正在考虑用 python 或 lisp 编写一个位板。但我不知道如何确保在 python 中获得 64 位整数。我一直在阅读文档,发现 mpz 库返回一个无符号 32 位整数。这是真的吗?如果不是我该怎么办?
So I am thinking of writing a bitboard in python or lisp. But I don't know how to ensure I would get a 64 bit integer in python. I have been reading documentation and found that mpz library returns a unsigned 32 bit integer. Is this true? If not what should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Python 2 有两种整数类型:
int
,它是一个有符号整数,其大小等于机器的字大小(但始终至少为 32 位),以及long
,它是大小不受限制。Python 3 只有一种整数类型,称为
int
,但相当于 Python 2long
。Python 2 has two integer types:
int
, which is a signed integer whose size equals your machine's word size (but is always at least 32 bits), andlong
, which is unlimited in size.Python 3 has only one integer type, which is called
int
but is equivalent to a Python 2long
.使用 gmpy 时,您有多种选择。下面是一个使用 gmpy 的示例:
gmpy2 是 gmpy 的开发版本,包含一种名为 xmpz 的新类型,它允许更直接地访问位。
您可能还想查看其他解决方案,例如 bitarray 。
免责声明:我维护 gmpy 和 gmpy2。
You have a couple of options using gmpy. Here is one example using gmpy:
gmpy2 is the development version of gmpy and includes a new type called xmpz that allows more direct access to the bits.
There are other solutions such as bitarray you might want to look at.
Disclaimer: I maintain gmpy and gmpy2.