移位运算

作者: 今天比昨天努力 | 来源:发表于2019-10-21 12:48 被阅读0次

    1,<< :左移运算符,

    System.out.println(1<<1);//2

    System.out.println(1<<2);//2*2

    System.out.println(1<<3);//2*2*2

    2,>>: 右移运算符

    System.out.println(16>>1);//16/2

    System.out.println(16>>2);// 16/2/2

    System.out.println(16>>3);// 16/2/2/2

    3,>>>: 无符号右移运算符

    System.out.println(0x7ffffff); //134217727

    System.out.println(0x7ffffff>>>24); //右移24位获取高8位 ----7

    System.out.println(0x7ffffff>>>16);//134217727 / 2^16

    System.out.println(0x7ffffff>>>8);//  134217727/ 2^8

    System.out.println(0x7ffffff>>>0);//  34217727/ 2^0

    4,<<<:无符号左移运算符

    System.out.println(1<<<1);//2

    System.out.println(1<<<2);//2*2

    System.out.println(1<<<3);//2*2*2

    相关文章

      网友评论

        本文标题:移位运算

        本文链接:https://www.haomeiwen.com/subject/pbpgyctx.html