<tfoot id='8TfsD'></tfoot>
      • <bdo id='8TfsD'></bdo><ul id='8TfsD'></ul>

      <small id='8TfsD'></small><noframes id='8TfsD'>

      <legend id='8TfsD'><style id='8TfsD'><dir id='8TfsD'><q id='8TfsD'></q></dir></style></legend>

      <i id='8TfsD'><tr id='8TfsD'><dt id='8TfsD'><q id='8TfsD'><span id='8TfsD'><b id='8TfsD'><form id='8TfsD'><ins id='8TfsD'></ins><ul id='8TfsD'></ul><sub id='8TfsD'></sub></form><legend id='8TfsD'></legend><bdo id='8TfsD'><pre id='8TfsD'><center id='8TfsD'></center></pre></bdo></b><th id='8TfsD'></th></span></q></dt></tr></i><div id='8TfsD'><tfoot id='8TfsD'></tfoot><dl id='8TfsD'><fieldset id='8TfsD'></fieldset></dl></div>

      1. 在 Java 中声明一个 unsigned int

        时间:2023-10-01
          <bdo id='Uxr5j'></bdo><ul id='Uxr5j'></ul>

                    <tbody id='Uxr5j'></tbody>
                • <legend id='Uxr5j'><style id='Uxr5j'><dir id='Uxr5j'><q id='Uxr5j'></q></dir></style></legend>

                  <small id='Uxr5j'></small><noframes id='Uxr5j'>

                • <i id='Uxr5j'><tr id='Uxr5j'><dt id='Uxr5j'><q id='Uxr5j'><span id='Uxr5j'><b id='Uxr5j'><form id='Uxr5j'><ins id='Uxr5j'></ins><ul id='Uxr5j'></ul><sub id='Uxr5j'></sub></form><legend id='Uxr5j'></legend><bdo id='Uxr5j'><pre id='Uxr5j'><center id='Uxr5j'></center></pre></bdo></b><th id='Uxr5j'></th></span></q></dt></tr></i><div id='Uxr5j'><tfoot id='Uxr5j'></tfoot><dl id='Uxr5j'><fieldset id='Uxr5j'></fieldset></dl></div>
                  <tfoot id='Uxr5j'></tfoot>
                  本文介绍了在 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 没有 无符号整数.

                  您可以定义一个 long 如果您需要存储大值,而不是 int.

                  您也可以像使用无符号整数一样使用有符号整数.二的补码表示的好处是大多数运算(例如加法、减法、乘法、和左移)在有符号和无符号整数的二进制级别上是相同的.然而,一些操作(除法、右移、比较和强制转换)是不同的.从 Java SE 8 开始, 中的新方法Integer 类允许您充分使用 int 数据类型 执行无符号算术:

                  You can also use a signed integer as if it were unsigned. The benefit of two's complement representation is that most operations (such as addition, subtraction, multiplication, and left shift) are identical on a binary level for signed and unsigned integers. A few operations (division, right shift, comparison, and casting), however, are different. As of Java SE 8, new methods in the Integer class allow you to fully use the int data type to perform unsigned arithmetic:

                  在 Java SE 8 及更高版本中,可以使用 int 数据类型来表示一个无符号的 32 位整数,其最小值为 0,最大值为 2^32-1.使用 Integer 类将 int 数据类型用作无符号整数.静态方法,例如 compareUnsigned, divideUnsigned 等已添加到 Integer 类中,以支持无符号整数的算术运算.

                  In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 2^32-1. Use the Integer class to use int data type as an unsigned integer. Static methods like compareUnsigned, divideUnsigned etc have been added to the Integer class to support the arithmetic operations for unsigned integers.

                  请注意,int 变量在声明时仍然是有符号的,但现在可以通过使用 Integer 类中的这些方法来进行无符号运算.

                  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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么我不能添加两个字节并获得一个 int,而我 下一篇:用逗号将整数转换为字符串数千

                  相关文章

                  最新文章

                        <bdo id='mTqms'></bdo><ul id='mTqms'></ul>

                      <small id='mTqms'></small><noframes id='mTqms'>

                    1. <i id='mTqms'><tr id='mTqms'><dt id='mTqms'><q id='mTqms'><span id='mTqms'><b id='mTqms'><form id='mTqms'><ins id='mTqms'></ins><ul id='mTqms'></ul><sub id='mTqms'></sub></form><legend id='mTqms'></legend><bdo id='mTqms'><pre id='mTqms'><center id='mTqms'></center></pre></bdo></b><th id='mTqms'></th></span></q></dt></tr></i><div id='mTqms'><tfoot id='mTqms'></tfoot><dl id='mTqms'><fieldset id='mTqms'></fieldset></dl></div>
                      <tfoot id='mTqms'></tfoot>

                    2. <legend id='mTqms'><style id='mTqms'><dir id='mTqms'><q id='mTqms'></q></dir></style></legend>