4

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

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

Please help me!

Perception
  • 79,279
  • 19
  • 185
  • 195
thuclh
  • 169
  • 1
  • 2
  • 5

2 Answers2

6

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
5

Java Operators

Bitwise Operations

<< is the left bit shift operator.

Jeffrey
  • 44,417
  • 8
  • 90
  • 141