Java中按位异或的作用是什么? [英] What does a bitwise exclusive OR do in Java?

查看:194
本文介绍了Java中按位异或的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出:

public class Spock {
    public static void main(String[] args) {
        Long tail = 2000L;
        Long distance = 1999L;
        Long story = 1000L;
        if ((tail > distance) ^ ((story * 2) == tail)) {
            System.out.print("1");
        }
        if ((distance + 1 != tail) ^ ((story * 2) == distance)) {
            System.out.print("2");
        }
    }
}

为什么此示例代码不输出任何内容?

Why this sample code doesn't output anything?

推荐答案

如果您首先获得true ^ true = false
如果获得false ^ false = false
,则在第二秒 因为^-是OR exclusive管理员,所以是

In first if you get true ^ true = false
In second if you get false ^ false = false
becouse ^ - is OR exclusive opeartor, it's means

true ^ true = false  
true ^ false = true 
false ^ true = true 
false ^ false = false

这篇关于Java中按位异或的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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