【问题标题】:I am using operator | and & but not getting proper answer我正在使用运算符 |和 & 但没有得到正确的答案
【发布时间】:2013-08-29 17:11:58
【问题描述】:
public class num {
    public static void main(String args[]) {
        int i = 5, j = 9, k = 3;
        int w, x;
        w = i | j | k;
        x = i &j & k;
        System.out.println(w);
        System.out.println(x);
    }
}

为什么w = 15x = 1 是值?

【问题讨论】:

  • 你期待什么答案?

标签: java bit-manipulation operator-keyword


【解决方案1】:

&|bitwise operators(分别为 AND 和 OR)。

5 ->  101
3 ->   11
9 -> 1001
     ----
AND  0001 = 1
OR   1111 = 15

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多