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

    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 }

  • 相关阅读:
    MySQL锁概述
    MYSQL删除重复记录
    SPRING事务控制
    性能测试中如何确定并发用户数
    Jsoup操作
    linux根据端口号查询进程
    linux下解压jar文件
    开发阶段的logback.xml
    栈--getMin(leetcode 155)
    git "fatal: The remote end hung up unexpectedly"
  • 原文地址:https://www.cnblogs.com/bzfsdr/p/13275018.html
Copyright © 2011-2022 走看看