显示非常大的数字
我们知道4294967295是unsigned int
中最大的数字,如果我把这个数字乘以它自己,那么如何显示它呢?我已经尝试过:
long unsigned int NUMBER = 4294967295 * 4294967295;
但仍然得到 1 作为答案。
As we know that 4294967295 is the largest number in unsigned int
if I multiply this number by itself then how to display it? I have tried:
long unsigned int NUMBER = 4294967295 * 4294967295;
but still getting 1 as answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
乘法溢出。
The multiplication overflows.
您在问题中声明您知道 max int 等于 4294967295。这意味着如果您使用 unsigned int,则无法存储大于该数字的数字。
在 64 位 unix 系统上未签名时,C long 最多可存储 18,446,744,073,709,551,615 [source] 所以你只需要在你的号码后面加上 UL 后缀:
4294967295UL
如果您使用的不是 64 位 UNIX 系统,那么您应该使用
long long unsigned int
并带有LL
后缀You state in your question that you know max int is equal to 4294967295. That means that you can't store a number larger than that if you are using unsigned int.
C longs store up to 18,446,744,073,709,551,615 when unsigned on a 64 bit unix system [source] so you need only suffix your numbers with UL :
4294967295UL
If you aren't using a 64-bit unix system then you should use
long long unsigned int
and suffix withLL
是的,这是溢出。如果您使用c,则没有任何简单的方法可以进行如此大的数字乘法,正如我所知。也许你需要自己写一份。事实上,有些语言本来就支持这样的功能。
Yes, it's an overflow. If you are using c, there isn't any easy way to do such big number multiply as i knew. Maybe you need write one by yourself. In fact some language support such features originally.
你正在溢出。考虑十六进制的乘法:
解决方案是使用更大的类型,例如
long long unsigned
:后缀
ULL
表示unsigned long long
。查看它在线运行:ideone
You are getting an overflow. Consider the muplication in hexadecimal:
The solution is to use a larger type such as
long long unsigned
:The suffix
ULL
meansunsigned long long
.See it working online: ideone