O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Shift Operators

There are three shift operators, used for changing the bit values in integral types. They aren't used frequently, except in programs that need to keep their memory usage to an absolute minimum. The shift operators are

  1. The left shift, represented as <<

  2. The signed right shift, represented as >>

  3. The unsigned right shift, represented as >>>

The left-hand side of the operators is the value to be shifted, and the right-hand side is the number of places to shift it. The type of each operand has to be an integral type, or a compiler error will occur. The shift happens on the 2's complement integer representation of the value on the left.

When the value to be shifted is an int, only the last 5 digits of the right-hand operand are used in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required