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

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

问题描述

我在Java中有以下语句:

I've got this statement in Java:

System.out.println(3|4); 

为什么输出7?

推荐答案

这是按位或运算.它在二进制级别上进行修改.

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.您可以在十进制和二进制(和十六进制)之间切换,并执行按位运算,包括or,and,xor等.

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天全站免登陆