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

    (很早的笔记,保存下)

    整数位运算:

    • 左移:正数右端补0,负数右端补1
    • 右移:正数左端补0,负数左端补1
    • 强制右移:不论正负数左端补0
    • 取反
    int a = 5;
    int b = -5;
    int c = (~5)+1;
    int d = a<<1;
    int e = b<<1;
    int f = a>>1;
    int g = b>>1;
    int h = a>>>1;
    int i = b>>>1;
    
    System.out.println("a:"+Integer.toBinaryString(a));
    System.out.println("b:"+Integer.toBinaryString(b));
    System.out.println("c:"+Integer.toBinaryString(c));
    System.out.println("d:"+Integer.toBinaryString(d));
    System.out.println("e:"+Integer.toBinaryString(e));
    System.out.println("f:"+Integer.toBinaryString(f));
    System.out.println("g:"+Integer.toBinaryString(g));
    System.out.println("h:"+Integer.toBinaryString(h));
    System.out.println("i:"+Integer.toBinaryString(i));
    //-------结果------------------------
    a:101
    b:11111111111111111111111111111011
    c:11111111111111111111111111111011
    d:1010
    e:11111111111111111111111111110110
    f:10
    g:11111111111111111111111111111101
    h:10
    i:1111111111111111111111111111101			//注意这里少一位
    
  • 相关阅读:
    各种模板
    HNOI2019总结
    WC2019游记
    THUSC2017 Day1题解
    NOIP2018联赛总结
    LOJ2557. 「CTSC2018」组合数问题
    NOI2018游记
    bzoj4671: 异或图
    sg函数小结
    [NOI2011]Noi嘉年华
  • 原文地址:https://www.cnblogs.com/cdbb/p/12558204.html
Copyright © 2011-2022 走看看