What does >> do in Java?

前端 未结 4 1752
夕颜
夕颜 2020-11-30 04:35

Okay, I tried looking up what >>, or shift means, but it\'s way over my head as this site explains it: http://www.janeg.ca/scjp/oper/shift.html

Wh

4条回答
  •  庸人自扰
    2020-11-30 04:39

    >> the SHIFT RIGHT operator

    Example:

    class X
          { 
           public static void main(String args[])
           {
             System.out.println("20>>2 = "+20>>2);
           }
          }        
    

    Output : 20>>2 = 5

    Explanation:

    Binary value of 20 is: 00000000000000000000000000010100

    shift all bits 2 positions to right 00000000000000000000000000000101

    It will give 5 ( 1*2^2 + 0*2^1 + 1*2^0 )

提交回复
热议问题