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?
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?
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 0
s (in binary, or 33554432
in decimal).