1
int x = 1 << 25;

What does the "<<" mean? Unsure of what this does, my ide gives me no errors though.. I've tried looking on forums and googling but could not find a solution. Any ideas?

frostmage
  • 109
  • 1
  • 1
  • 3
  • 6
    [Java Bitshift operations](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html) – Gordon Allocman Mar 29 '16 at 19:13
  • Also for future reference you can use SymbolHound (a search engine) that allows you to search without stripping symbols. For example [this](http://symbolhound.com/?q=%3C%3C+java) would be your search/results for this particular question – Gordon Allocman Mar 29 '16 at 19:15

1 Answers1

2

It's a left (bit) shift. JLS-15.19. Shift operators says (in part)

The operators << (left shift), >> (signed right shift), and >>> (unsigned right shift) are called the shift operators. The left-hand operand of a shift operator is the value to be shifted; the right-hand operand specifies the shift distance.

For a simple example, consider

System.out.println(Integer.toBinaryString(1));
System.out.println(Integer.toBinaryString(1 << 1));
System.out.println(Integer.toBinaryString(1 << 2));

Which outputs

1
10
100

as it shifts the single 1 bit left once and twice respectively.

In your example, int x = 1 << 25; that is a 1 followed by 25 0s (in binary, or 33554432 in decimal).

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249