本文介绍了在Java中声明unsigned int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Java中声明unsigned int?

Is there a way to declare an unsigned int in Java?

或者问题也可以这样构成:
什么是Java等价物未签名?

Or the question may be framed as this as well:What is the Java equivalent of unsigned?

只是告诉你我正在研究Java的实现 String.hashcode()。如果整数是32 unsigned int,我想测试碰撞的可能性。

Just to tell you the context I was looking at Java's implementation of String.hashcode(). I wanted to test the possibility of collision if the integer were 32 unsigned int.

推荐答案

Java没有。

你可以定义而不是 int 如果您需要存储大值,但无法排除负值。

You can define a long instead of an int if you need to store large values but there's no way to exclude negative values.

但是,从Java SE 8开始,类允许您使用 int 数据类型:

However, as of Java SE 8, there are a few new methods in the Integer class which allow you to use the int data type to perform unsigned arithmetic:

请注意, int 变量在声明时仍然是有符号的,但现在可以使用这些方法进行无符号算术在整数类中。

Note that int variables are still signed when declared but unsigned arithmetic is now possible by using those methods in the Integer class.

这篇关于在Java中声明unsigned int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 00:26
查看更多