• 位运算符


    1、&:与运算符

    二进制比较,都为1则为1,否则为0

    0=非=false,1=是=true

    & 类比 &&,当&&的所有条件都满足是才为true,故推到出上述结果。

    2、|:或运算符

    二进制比较,只要有一个为1就是1,否则为0

    与&类似

    3、~:非运算符

    二进制结果倒置,为0则1,1则0;

    类比!

    4、^:异或运算符

    二进制比较,相同为0,不同为1

    类比!=

    5、<<:左移运算符

    二进制,左移位数,低位补0

    6、>>:右移运算符

    二进制,右移位数

    值为正,高位补0

    值为负,高位补1

    7、>>>:右移运算符

    二进制,右移位数,无论正负高位都补0

     1 public static void main(String[] args) throws InterruptedException {
     2     // 11 1110 0111
     3     System.out.println(Integer.toBinaryString(999));
     4     // 1111 1111 1111 1111 1111 1100 0001 1001
     5     System.out.println(Integer.toBinaryString(-999));
     6     // 00 0001 1111
     7     System.out.println(Integer.toBinaryString(999 >>> 5));
     8     // 0000 0111 1111 1111 1111 1111 1110 0000
     9     System.out.println(Integer.toBinaryString(-999 >>> 5));
    10     // 1 1111 0011 1000 0000
    11     System.out.println(Integer.toBinaryString(999 << 7));
    12     // 1111 1111 1111 1110 0000 1100 1000 0000
    13     System.out.println(Integer.toBinaryString(-999 << 7));
    14     // 0 0011 1110 0111
    15     System.out.println(Integer.toBinaryString(999 >> 3));
    16     // 1111 1111 1111 1111 1111 1111 1000 0011
    17     System.out.println(Integer.toBinaryString(-999 >> 3));
    18 }

  • 相关阅读:
    如何使用Apache设置404页面
    字符串函数积累
    isset() unset()
    set_exception_handler 自定义异常处理
    phpMailer中文说明[转]
    我的PHPMailer_v5.1 使用
    PHPMailer_v5.1 使用[转]
    PHP错误和异常处理
    几个 PHP 的“魔术常量”
    九宫格布局(demo16.03.14)
  • 原文地址:https://www.cnblogs.com/bzfsdr/p/13275018.html
Copyright © 2020-2023  润新知