热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

java7中的管道运算符[重复]-Pipeoperatorinjava7[duplicate]

Thisquestionalreadyhasananswerhere:这个问题在这里已有答案:Pipe(|)operatorinJava7answe

This question already has an answer here:

这个问题在这里已有答案:

  • Pipe (|) operator in Java 7 answers
  • Java 7中的管道(|)操作符答案

I saw recently in a code example the following:

我最近在一个代码示例中看到了以下内容:

f.setExtendedState( f.getExtendedState()|JFrame.MAXIMIZED_BOTH );

where f is a JFrame. How is this pipe operator called, what does it do and where can I find documentation about it?

其中f是JFrame。这个管道操作员如何调用,它做了什么以及在哪里可以找到有关它的文档?

Thank you Héctor

谢谢Héctor

4 个解决方案

#1


0  

The | operator is the bitwise-or operator in Java.

| operator是Java中的按位或运算符。

The result of a bitwise-or is a value with bits set in it if the corresponding bit was set in either of the operands (or both).

如果在任一操作数(或两者)中设置了相应的位,则按位的结果或是设置了位的值。

Here, this operation uses the value of JFrame.MAXIMIZED_BOTH (in binary, 0000 0110) to ensure that the second to last and third to last bits are turned on, one for horizontal and one for vertical. This leaves all other bits from f.getExtendedState() intact.

这里,此操作使用JFrame.MAXIMIZED_BOTH(二进制,0000 0110)的值来确保打开倒数第二位和倒数第三位,一个用于水平,一个用于垂直。这使得f.getExtendedState()中的所有其他位保持不变。

#2


2  

That 'pipe' is actually a bitwise inclusive or. f.getExtendedState() and JFrame.MAXIMIZED_BOTH are probably number indexes in bitfields. using the 'or' operator combines the properties of both into one value.

那个'管道'实际上是一个包容性的或者。 f.getExtendedState()和JFrame.MAXIMIZED_BOTH可能是位域中的数字索引。使用'或'运算符将两者的属性组合成一个值。

#3


0  

| stands for bitwise inclusive OR operater. Check for details here:

|代表按位包含OR操作符。在这里查看详细信息:

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html

#4


0  

The pipe (|) operator is simply bitwise-or operator. It will go through the respective bits of two numbers, and the resulting number will have an on bit where either of the two input bits were on. In the case you gave us, the operator is used to add a flag to a bitfield.

管道(|)操作符只是按位或运算符。它将遍历两个数字的相应位,并且得到的数字将具有一个on位,其中两个输入位中的任何一个都打开。在您给我们的情况下,运算符用于向位域添加标志。

For example, if you have a number flags, which (let's say) is 4, it would look like

例如,如果你有一个数字标志,(比方说)是4,它看起来像

00000100b

in binary. If you | it with the number 00010000b (16), the result is

在二进制。如果你|它的编号为00010000b(16),结果是

00010100b,

which contains the original flag (at bit position 3) and the new flag (at bit position 5).

其中包含原始标志(位位置3)和新标志位(位位置5)。


推荐阅读
author-avatar
荆州房产网
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有