What does << or >>> mean in java?

Possible duplicate:
What is →> and → →> in Java?

I came across some unfamiliar characters in some kind of java code, and although the code compiles and functions correctly, I am confused by what exactly the angle brackets do in this code. I found the code in com.sun.java.help.search.BitBuffer , a snippet of which is below:

 public void append(int source, int kBits) { if (kBits < _avail) { _word = (_word << kBits) | source; _avail -= kBits; } else if (kBits > _avail) { int leftover = kBits - _avail; store((_word << _avail) | (source >>> leftover)); _word = source; _avail = NBits - leftover; } else { store((_word << kBits) | source); _word = 0; _avail = NBits; } } 

What do mysterious brackets do? It almost looks like C ++ insert / extract, but I know that Java has nothing of the kind.

Also, I tried to do a search on Google, but for some reason, Google doesn't seem to see angle brackets, even if I put them in quotation marks.

+6
source share
3 answers

They are bitwise shift operators, they work by changing the number of bits set. Here's a tutorial on how to use them.

The recorded left shift operator "<moves the bit to the left

The signed right shift operator "→" shifts the bit pattern to the right.

The unsigned right shift operator "→>" shifts zero to the leftmost position

+20
source

straight from ORACLE DOC .

The written left-shift operator "<shifts the bit to the left, and the signed left-shift operator" → "shifts the bit pattern by the correct one. The bit diagram is set by the left operand, and the number of positions to shift by the right operand. Unsigned, the right shift operator" →> shifts zero to the leftmost position, and the leftmost position after "→" depends on the expansion of the sign.

+4
source

All Articles