What is this expression in Java ( 1 << 2)?

后端 未结 2 648
慢半拍i
慢半拍i 2021-01-19 08:07

I don\'t know what this means \"1 << 2\" in :

public static final int MODIFY_METADATA = 1 << 2; // modify object

Please help m

相关标签:
2条回答
  • 2021-01-19 09:05

    If you want to know why would use use 1 << 2 rather than 4 which is the same value, it because you explicitly want to be using a bit mask e.g.

    public static final int FLAG0 = 1 << 0;
    public static final int FLAG1 = 1 << 1;
    public static final int MODIFY_METADATA = 1 << 2;
    

    Shows each value is in a bit mask.

    0 讨论(0)
  • 2021-01-19 09:06

    Java Operators

    Bitwise Operations

    << is the left bit shift operator.

    0 讨论(0)
提交回复
热议问题