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 }

  • 相关阅读:
    Java + Element-UI 实现简单的树形菜单
    Spring Boot 日志
    SpringMVC入门
    vue 路由钩子函数 刷新当前路由
    使用vue 路由钩子函数 报错 Uncaught (in promise) undefined
    Webpac优化看文记录
    移动端长按复制记录
    Vue.js 运行机制全局概览浅读
    老异步问题了
    vue-lazyload的使用 图片懒加载
  • 原文地址:https://www.cnblogs.com/bzfsdr/p/13275018.html
Copyright © 2011-2022 走看看