zoukankan      html  css  js  c++  java
  • java 运算符

    public class Demo02 {
        public static void main(String[] args) {
                int i1 = 128;
                int i2 = 129;
                System.out.println(Integer.toBinaryString(i1));
                System.out.println(Integer.toBinaryString(i2));
                System.out.println(Integer.toBinaryString(i2&i1));
                System.out.println(i1&i2);
        }
    }

    输出结果:

      10000000

      10000001

      10000000

      128

    ------------------------------------------------------------------------------------

    public class Demo02 {
        public static void main(String[] args) {
                int i1 = 128;
                int i2 = 129;
                System.out.println(Integer.toBinaryString(i1));
                System.out.println(Integer.toBinaryString(i2));
                System.out.println(Integer.toBinaryString(i2|i1));
                System.out.println(i1|i2);
        }
    }

    输出结果:

      10000000

      10000001

      10000001

      129

    ---------------------------------------------------------------------------

    public class Demo02 {
        public static void main(String[] args) {
                int i1 = 128;
                int i2 = 129;
                System.out.println(Integer.toBinaryString(i1));
                System.out.println(Integer.toBinaryString(i2));
                System.out.println(Integer.toBinaryString(i2^i1));
                System.out.println(i1^i2);
        }
    }

    输出结果:

      10000000

      10000001

      00000001(应该是1,但是为了方便理解)

      1

    ---------------------------------------------------------------------------------

    public class Demo02 {
        public static void main(String[] args) {
                int i1 = 128;
                int i2 = 129;
                System.out.println(Integer.toBinaryString(i1));
                System.out.println(Integer.toBinaryString(i2));
                System.out.println(Integer.toBinaryString(~i1));
                System.out.println(~i1);
        }
    }

    输出结果:

      10000000

      10000001

      11111111111111111111111101111111

      -129

    ------------------------------------------------------------------------------------

    上述结果可以得出结论:

      &(与):两个操作数中位都为1,结果才为1,否则结果为0;

      |(或):两个操作数有一个为1时,结果就为1,否则结果为0;

      ^(异或):两个操作数不同时,结果为1,否则结果为0;

      ~(非):如果位为0,结果为1,反之,结果为0;

  • 相关阅读:
    mysql-8.0.16-winx64/Linux修改root用户密码
    MYSQL学习笔记/2019
    博客论坛系统数据库之表的设计
    MySql-8.0.16版本部分安装问题修正
    将博客搬至CSDN
    解决远程连不到CentOS7虚拟机或ifconfig中没有ens33
    Windows本地运行调试Spark或Hadoop程序失败:ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path
    CentOS7安装Git-2.22.1
    CentOS7安装SVN1.9.12
    Storm本地启动拓扑报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/storm/topology/IRichSpout
  • 原文地址:https://www.cnblogs.com/hongcong/p/5764641.html
Copyright © 2011-2022 走看看