i was just looking over someone elses code and i came across the line of code
static final int DONE = (1 << 9) - 1;
could someone please example to me what the (1 << 9) -1 part it doing? ive not seen the << symbol used in any code before.
Printable View
i was just looking over someone elses code and i came across the line of code
static final int DONE = (1 << 9) - 1;
could someone please example to me what the (1 << 9) -1 part it doing? ive not seen the << symbol used in any code before.
You will want to look up bit shifting to see what this does. Also, when I run across something I don't fully understand, I run little test programs to see what it does, i.e.,
Code:public class Fu1 {
public static void main(String[] args) {
for (int i = 0; i < 12; i++) {
int shiftedBit = (1 << i);
System.out.printf("Shifted by %2d: %d%n", i, shiftedBit);
}
}
}
<< just move bits to left.
It is also useful pair as >> too :)
byte boo=3<<1;
the code should move one bit to left I guess...
read this to know more Bitwise operation - Wikipedia, the free encyclopedia