-3

I looked at the method which convert ByteArray to int in this topic, and I feel a little bit confused when I look at this line:

ret[2] = (byte) ((a >> 8) & 0xFF);
if >> operator means this same as > operator when we working with int/float..? When they are not equal, what is the meaning of it?

Community
  • 1
  • 1
MyWay
  • 1,011
  • 2
  • 14
  • 35
  • 2
    Search for `java operators`. – Sotirios Delimanolis Oct 18 '13 at 13:32
  • That means , not a good question and read [java operators](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html) docs. – Suresh Atta Oct 18 '13 at 13:32
  • yeah i get it http://www.tutorialspoint.com/java/java_basic_operators.htm i don't know if i should delete this topic – MyWay Oct 18 '13 at 13:33
  • these are bit wise operator. read java operators. – HackerGK Oct 18 '13 at 13:33
  • +1. Just because something can be found in a Javadoc does not mean it shouldn't exist as a question on Stack Overflow. @SotiriosDelimanolis "Search for java operators"... maybe somebody will do that and find this question. It's useful. – James Dunn Oct 18 '13 at 14:05
  • @TJamesBoone You will notice, if you hover over the downvote arrow, `this question does not show any research effort`. OP could have take their title and put it in SO's search field with `java` and found the answer. This is also a duplicate. – Sotirios Delimanolis Oct 18 '13 at 14:08
  • @SotiriosDelimanolis Good point about duplicate. It's unfortunate, because Pignic's answer is better than the answers on the original question. – James Dunn Oct 18 '13 at 14:33

2 Answers2

3
8 >> 2 = 2
8 >> 3 = 1

in binary

00001000 >> 2 = 00000010
00001000 >> 3 = 00000001

And

1 << 2 = 4
1 << 3 = 8

in binary :

00000001 << 2 = 00000100
00000001 << 3 = 00001000

use ~ to negate :

byte b = ~01001000

then b is 10110111

The & operator is a bit intersection

10010101 & 01010011 = 00010001

And many others operator exist, and this is a very powerful way to do many things

Pignic
  • 499
  • 3
  • 12
-1

The right shift >> operator shifts the left operand to the right side with sign extension by the number of bits specified by its right operand. This means that a value at n place gets shifted to the right causing the n high order bits that contains the same value as that of unshifted value. This operator never throws an exception.

While > operator is simply used for comparison

Scientist
  • 1,458
  • 2
  • 15
  • 31