读书笔记20200409运算

private static Integer a = 128;
    private static Integer b = 129;
    public static void main(String[] args) {
        a();
        b();
        c();
        d();
    }

    /**
     * 与运算
     */
    public static void a(){
        System.out.println("与运算");
        System.out.println(Integer.toBinaryString(a)+"&"+Integer.toBinaryString(b));
        System.out.println(Integer.toBinaryString(a&b));
        System.out.println(a+"&"+b);
        System.out.println(a&b);
    }
    /**
     * 或运算
     */
    public static void b(){
        System.out.println("或运算");
        System.out.println(Integer.toBinaryString(a)+"|"+Integer.toBinaryString(b));
        System.out.println(Integer.toBinaryString(a|b));
        System.out.println(a+"|"+b);
        System.out.println(a|b);
    }
    /**
     * 非运算
     */
    public static void c(){
        System.out.println("非运算");
        System.out.println("~"+Integer.toBinaryString(a));
        System.out.println(Integer.toBinaryString(+(~a)));
        System.out.println("~"+a);
        System.out.println(~a);
    }
    /**
     * 异或运算
     */
    public static void d(){
        System.out.println("异或运算");
        System.out.println(Integer.toBinaryString(a)+"^"+Integer.toBinaryString(b));
        System.out.println(Integer.toBinaryString(a^b));
        System.out.println(a+"^"+b);
        System.out.println(a^b);
    }


与运算
10000000&10000001
10000000
128&129
128
或运算
10000000|10000001
10000001
128|129
129
非运算
~10000000
11111111111111111111111101111111
~128
-129
异或运算
10000000^10000001
1
128^129
1

1.与运算符
与运算符用符号“&”表示,其使用规律如下:
两个操作数中位都为1,结果才为1,否则结果为0

2.或运算符
或运算符用符号“|”表示,其运算规律如下:
两个位只要有一个为1,那么结果就是1,否则就为0

3.异或运算符
异或运算符是用符号“^”表示的,其运算规律是:
两个操作数的位中,相同则结果为0,不同则结果为1

4.非运算符
非运算符用符号“~”表示,其运算规律如下:

如果位为0,结果是1,如果位为1,结果是0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值