Java 中的管道 (|) 运算符 [英] Pipe (|) operator in Java

查看:20
本文介绍了Java 中的管道 (|) 运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Java 中有这样的声明:

I've got this statement in Java:

System.out.println(3|4); 

为什么输出是 7?

推荐答案

这是一个按位 OR 操作.它正在二进制级别修改内容.

It's a bitwise OR operation. It's modifying things at a binary level.

             011                     3
in binary: | 100     in decimal:  |  4
             ___                   ___
             111                     7

使用科学模式打开 Windows calc.您可以在十进制和二进制(和十六进制)之间切换,并执行按位运算,包括或、与、异或等.

Open Windows calc using scientific mode. You can flip between decimal and binary (and hex) and perform bitwise operations including or, and, xor, etc.

要按位或在头脑中或在纸上进行,请比较相同序数的每个数字.如果任一数字为 1,则该序号的结果将为 1.

To do a bitwise or in your head or on paper, compare each digit of the same ordinal. If either number is a 1, the result at that ordinal will be 1.

这篇关于Java 中的管道 (|) 运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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