-6

I found this integer variable declaration in a Java class:

int i7 = ((0x1F & arrayOfByte[i][4]) << 9) + ((0xFF & arrayOfByte[i][5]) << 1) + (0x1 & (0xFF & arrayOfByte[i][6]) >>> 7);

But are the arrows (>>> and <<) mean/doing?

Kind regards, Bastiaan

UPDATE: Sow they are bitshift operators, thanks! Found this good explanation video: https://www.youtube.com/watch?v=1qa0zvcdHXI

  • 5
    http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html – VM4 Sep 02 '14 at 20:33
  • >> bitshift right, << bitshift left, >>> looping bitshift right, <<< looping bitshift left (while looping means that the bit comes in on the other side of the 32 bit integer again) – TheWhiteLlama Sep 02 '14 at 20:34
  • Look who didn't do his research homework. – Gumbo Sep 02 '14 at 20:37
  • 4
    @TheWhiteLlama This is misinformation. `>>>` is not a looping bit shift, and `<<<` is not legal Java. – ajb Sep 02 '14 at 20:39

1 Answers1

3

Throughout this post let's assume numbers are one hex digit, just for simplicity.

">>" is the bit shift operator. For example:

8 >> 1 == 8 / 2 == 4;

Which in binary is equivalent to

b1000 >> 1 == b0100;

Adding the third ">" into the operator inserts a 0 into the now far left slot, instead of doing sign extension to determine it's value.

-1 >> 1 = b1111
-1 >>> 1 = b0111

This is more useful for things like bit masks, where forcing the new value to 0 is convenient. And is only applicable to right shifting, there is no <<< operator.

MobA11y
  • 18,425
  • 3
  • 49
  • 76