通常大数字变为负数 [英] Often big numbers become negative

查看:185
本文介绍了通常大数字变为负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从我开始将eclipse用于项目euler以来,我注意到大数字有时会变成看似随机的负数。我想这与传递类型的boudry有关。

Since I started using eclipse for project euler, I noticed that big numbers sometime become a seemingly random negative numbers. I suppose this has something to do with passing the boudry of the type.

如果你能向我解释这些负数是如何生成的,那么我会很高兴它背后的逻辑。另外,我怎样才能避免它们(最好不要使用BigInteger类)。 Danke!=)

I'll be glad if you could explain to me how these negative numbers are generated and what is the logic behind it. Also, how can I avoid them (preferable not with BigInteger class). Danke!=)

推荐答案

此图显示了您要查找的内容。在你的情况下,它显然是更大的数字,但原则保持不变。



java中的限制示例如下:

int:-2,147,483,648 to 2,147,483,647。

长:-9,223,372,036,854,775,808到9,223,372,036,854,775,807

This image shows what you're looking for. In your case it's obviously larger numbers, but the principle stays the same.

Examples of limits in java are:
int: −2,147,483,648 to 2,147,483,647.
long: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807


在图像0000,0001等中,显示数字的二进制表示。


In the image 0000, 0001 etc, shows the binary representation of the numbers.

编辑:在项目euler中,你经常需要考虑一种解决滞后数字的方法。这些问题的设计数字很大,因此您无法使用普通的问题解决方法。但是,如果你发现你确实需要使用它们,我建议无论如何都要研究BigInteger。从长远来看,你会发现它很有用,并不是那么复杂。以下链接包含许多可以理解的示例:
BigInteger示例

In project euler you often have to think of a way to work around the lagre numbers. The problems are designed with numbers that big so that you can't use the ordinary way of problem solving. However, if you find that you really need to use them, i suggest studying BigInteger anyway. You will find it useful in the long run, and it's not all that complicated. Here is a link with lots of understandable examples: BigInteger Example

这篇关于通常大数字变为负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆