<tfoot id='b4ndJ'></tfoot>

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

      1. value &amp; 是什么意思?0xff 在 Java 中做什么?

        What does value amp; 0xff do in Java?(value amp; 是什么意思?0xff 在 Java 中做什么?)
            <tbody id='lbAFo'></tbody>

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

                  <tfoot id='lbAFo'></tfoot>
                  <legend id='lbAFo'><style id='lbAFo'><dir id='lbAFo'><q id='lbAFo'></q></dir></style></legend>
                • <small id='lbAFo'></small><noframes id='lbAFo'>

                  本文介绍了value &amp; 是什么意思?0xff 在 Java 中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下 Java 代码:

                  I have the following Java code:

                  byte value = 0xfe; // corresponds to -2 (signed) and 254 (unsigned)
                  int result = value & 0xff;
                  

                  打印时的结果是 254,但我不知道这段代码是如何工作的.如果 & 运算符只是按位操作,那么为什么它不会产生一个字节而是一个整数呢?

                  The result is 254 when printed, but I have no idea how this code works. If the & operator is simply bitwise, then why does it not result in a byte and instead an integer?

                  推荐答案

                  它将 result 设置为将 value 的 8 位放入result 的最低 8 位.

                  It sets result to the (unsigned) value resulting from putting the 8 bits of value in the lowest 8 bits of result.

                  之所以需要这样的东西是因为 byte 在 Java 中是一个有符号类型.如果你只是写:

                  The reason something like this is necessary is that byte is a signed type in Java. If you just wrote:

                  int result = value;
                  

                  然后 result 将以 ff ff ff fe 值结束,而不是 00 00 00 fe.更微妙的是,& 被定义为仅对 int1 进行操作,所以发生的情况是:

                  then result would end up with the value ff ff ff fe instead of 00 00 00 fe. A further subtlety is that the & is defined to operate only on int values1, so what happens is:

                  1. value 被提升为 int (ff ff ff fe).
                  2. 0xffint 文字(00 00 00 ff).
                  3. 应用 & 以产生 result 的所需值.
                  1. value is promoted to an int (ff ff ff fe).
                  2. 0xff is an int literal (00 00 00 ff).
                  3. The & is applied to yield the desired value for result.

                  (关键是转换为 int 发生在 应用 & 运算符之前.)

                  (The point is that conversion to int happens before the & operator is applied.)

                  1嗯,不完全是.如果任一操作数是 long& 运算符也适用于 long 值.但不在 byte 上.请参阅 Java 语言规范, 部分15.22.1 和 5.6.2.

                  1Well, not quite. The & operator works on long values as well, if either operand is a long. But not on byte. See the Java Language Specification, sections 15.22.1 and 5.6.2.

                  这篇关于value &amp; 是什么意思?0xff 在 Java 中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)

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

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

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

                            <tfoot id='N43ml'></tfoot>