0

I searched all over internet, but I can't find it, I read a book on Java game programming and the code is this.

public void move (int x, Rectangle bd) {
    if (x > (width >> 1) && x < (bd.width - (width >> 1))) {
        this.x = x;
    }
}

I don't understand what does it means, please help me.

Alex
  • 163
  • 7
Sr1871
  • 218
  • 1
  • 8
  • 2
    The problem is you need to know the name to search for it. It's a bitwise operator, more specifically a shift. – Denys Séguret May 27 '15 at 06:51
  • @DenysSéguret is right - see: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html – Frank May 27 '15 at 06:55
  • in the context above >> 1 is performing a "divide by 2" - not shifting the bits for any "bitwise" reason. shifting >> 2 would be divide by 4. >> 3 would be divide by 8. in the bad old days, actual divide operations used to be very expensive relative to other instructions and the speed of the machine itself so its see as a cheap optimisation. not sure how relevant it is these days though. compilers would often convert a /2 into a >>1 etc – slipperyseal May 27 '15 at 06:56
  • thanks, I remembered to have listened that it serve for something about bits, but I thought that in this case it doesn't had sense that. I think that the other way that give me is the correct in this case Now I understand and if I have another question with the name of the operator is easier find answer on internet thanks! – Sr1871 May 27 '15 at 07:12

0 Answers0