Java operators

Java operators

What is the difference between the >> and >>> operators?
View Answers

October 26, 2010 at 1:00 PM

Hi,

Here is the answer.

">>" is a signed right shift, while ">>>" is an unsigned right shift. What this means is that if you use a signed shift on a negative number, the result will still be negative. Signed right shifting by one is equivalent to dividing by two, even if the number is negative.

Unsigned shifting, on the other hand, ignores the sign of the number, and unsigned right shifting a negative number will result in a positive number -- which is why you generally shouldn't use the unsigned shift unless you are considering your number as unsigned.

The reason for the difference is that bytes, shorts, ints, and longs are all stored in two's-complement form (i.e. as signed numbers). This means, among other things, that the most significant bit is the sign bit, so that if the sign bit is 0 the number is positive, and if the sign bit is 1 the number is negative. If you want to divide a signed number by two by shifting it right, you have to retain the sign bit.

Another way of thinking about the difference between the operators is that the signed shift fills from the left with the sign bit (0 or 1), and the unsigned shift zero-fills from the left.

Thanks.









Related Tutorials/Questions & Answers:
Java operators
Java operators  What is the difference between the >> and >>> operators
Java operators
Java operators  What is the % operator
Advertisements
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Operators in java 7
This tutorial describes the concept of operators in java 7
Operators In Java
Operators In Java In this section we will read about operators in Java. We will illustrate the use of operators in Java using a simple example. Java provides various operators to manipulate the operations in Java. Operators
java operators - Java Beginners
java operators  Hello...........Can we perform addition of two numbers without using any arithmatic operator?  Hi Friend, Yes, you can use BigInteger class to add, subtract,multiply,divide the numbers: import
operators
operators  Create a simple java program that adds, subtracts, divides and multiplies any two numbers that are entered by a user
Unary Operators in java 7
In this section you will learn about the Unary operators. This is one type of operators
Bitwise Operators in java 7
In this section you will learn about the Bitwise Operators. This is one type of operators
Arithmetic Operators in java 7
In this section you will learn about the Arithmetic operators. This is one type of operators
Other Operators in java 7
Other Operators in java 7 In this section you will learn about the Other Operators. This is one type of operators. Conditional Operator (? :): This is also called ternary operator. It contains three operand and two operators
Relational Operators in java 7
Relational Operators in java 7 In this section you will learn about the Equality and Relational operators. This is one type of operators. Equality and Relational Operators : Equality operator checks for equality of operands
Operators
Operators       Operators are symbols that performs some operations on one or more then one operands. Once we declare and initialize variables, we can use operators to perform
Operators
Operators       Operators are symbols that performs some operations on one or more then one operands. Once we declare and initialize variables, we can use operators to perform
Assignment Operators in java 7
Assignment Operators in java 7 In this section you will learn about the Assignment Operators. This is one type of operators. Assignment Operators : This operator is used whenever you need to assign some value to your variables. You
ciruit operators.
ciruit operators.  Explain the benefit of short ciruit operators
difference between == and === operators?
difference between == and === operators?  Is (====) operator available in java or not? difference between
bitwise operators
bitwise operators  Write short note on bitwise operators of Java.   Please visit the following links: http://www.roseindia.net/java/java-tips/data/expressions/slides-bitops.shtml http://www.roseindia.net/java/java
Operators
Operators       Operators are symbols that performs some operations on one or more than one operands. Once we declare and initialize variables, we can use operators to perform
Operators
Operators       Operators are symbols that performs some operations on one or more then one operands. Once we declare and initialize variables, we can use operators to perform
The Unary Operators
The Unary Operators in Java   ... operator. In java we have been provided the unary operators so we should know how... will know how to make use of the unary  operators in java. First all of, we have
Operators and Expressions
to perform certain tasks like assigning a value, adding the numbers etc. Java operators... Operators Expressions: In Java, an expression is like a statement without... Operators and Expressions   
boolean operators in JavaScript
boolean operators in JavaScript  What boolean operators does JavaScript support
logical operators in objective c
logical operators in objective c  logical operators in objective c
operators
operators
SQL OR Operators
SQL OR Operators       The OR operator displays records if any of the conditions is true. 1st Condition 2nd Condition Result false
SQL AND Operators
SQL AND Operators       The AND operator displays records if both conditions are true. 1st Condition 2nd Condition Result false
What is the difference between the >> and >>> operators?
What is the difference between the >> and >>> operators?   hi, What is the difference between the >> and >>> operators? Thanks
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.10.1.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.10.1.Final in Maven based Java projects
-operators version 2.10.1.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.10.1.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.10.1.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.14.0.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.14.0.Final in Maven based Java projects
-operators version 2.14.0.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.14.0.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.14.0.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.14.2.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.14.2.Final in Maven based Java projects
-operators version 2.14.2.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.14.2.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.14.2.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.13.4.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.13.4.Final in Maven based Java projects
-operators version 2.13.4.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.13.4.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.13.4.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.14.3.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.14.3.Final in Maven based Java projects
-operators version 2.14.3.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.14.3.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.14.3.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.14.3.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.14.3.Final in Maven based Java projects
-operators version 2.14.3.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.14.3.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.14.3.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.13.6.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.13.6.Final in Maven based Java projects
-operators version 2.13.6.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.13.6.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.13.6.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.15.1.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.15.1.Final in Maven based Java projects
-operators version 2.15.1.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.15.1.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.15.1.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.11.2.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.11.2.Final in Maven based Java projects
-operators version 2.11.2.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.11.2.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.11.2.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.12.2.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.12.2.Final in Maven based Java projects
-operators version 2.12.2.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.12.2.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.12.2.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.12.0.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.12.0.Final in Maven based Java projects
-operators version 2.12.0.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.12.0.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.12.0.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.13.0.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.13.0.Final in Maven based Java projects
-operators version 2.13.0.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.13.0.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.13.0.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.11.3.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.11.3.Final in Maven based Java projects
-operators version 2.11.3.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.11.3.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.11.3.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.13.3.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.13.3.Final in Maven based Java projects
-operators version 2.13.3.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.13.3.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.13.3.Final java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 3.0.0.Alpha1 is released. Learn to use quarkus-mutiny-reactive-streams-operators version 3.0.0.Alpha1 in Maven based Java projects
-operators version 3.0.0.Alpha1 ) in their Java project if it is based on Maven...-reactive-streams-operators version 3.0.0.Alpha1 in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 3.0.0.Alpha1 java
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.14.0.CR1 is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.14.0.CR1 in Maven based Java projects
-streams-operators version 2.14.0.CR1 in Java projects. Follow the step by step... - quarkus-mutiny-reactive-streams-operators version 2.14.0.CR1 java library in your...-mutiny-reactive-streams-operators released The developers of  
Maven dependency for io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.10.3.Final is released. Learn to use quarkus-mutiny-reactive-streams-operators version 2.10.3.Final in Maven based Java projects
-operators version 2.10.3.Final ) in their Java project if it is based on Maven...-reactive-streams-operators version 2.10.3.Final in Java projects. Follow the step...; io.quarkus - quarkus-mutiny-reactive-streams-operators version 2.10.3.Final java

Ads