Java Right Shift Operator

Chapter: Operators Last Updated: 13-12-2016 15:46:37 UTC

Program:

            /* ............... START ............... */
                
public class JavaRightShiftOperator {

	public static void main(String args[]) {

		int x = -4;
		System.out.println(x >> 1);
		int y = 4;
		System.out.println(y >> 1);

	}
}
                /* ............... END ............... */
        

Output

-2
2

Notes:

  • In Java, the operator ‘>>’ is signed right shift operator. All integers are signed in Java, and it is fine to use >> for negative numbers. The operator ‘>>’ uses the sign bit (left most bit) to fill the trailing positions after shift. If the number is negative, then 1 is used as a filler and if the number is positive, then 0 is used as a filler. For example, if binary representation of number is 10….100, then right shifting it by 2 using >> will make it 11…….1.

Tags

Right Shift Operator, Java, Operators

Similar Programs Chapter Last Updated
Java Left Shift Operator Operators 04-09-2018
Java Addition Operator Operators 18-05-2017
Prefix Operator In Java Example Operators 19-06-2016
Logical Operators In Java Example Operators 17-06-2016
Operator Precedence In Java Examples Operators 17-06-2016
Ternary Operators In Java Example Operators 15-07-2016
Relational Operators In Java Example Operators 11-06-2016
Modulus Operators In Java Example Operators 15-07-2016
Increment And Decrement In Java Example Operators 15-07-2016
Boolean Operator In Java Example Operators 15-07-2016
Bitwise Operator In Java Example Operators 16-06-2017
Assignment Operation In Java Example Operators 06-04-2016
Arithmetic Operation In Java Example Operators 11-06-2016

1