This week's giveaway is in the Java/Jakarta EE forum.We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Some arithmetic problems

Ranch Hand
Posts: 61
I faced this problem

int x = -8;
int y = ~-33;
x>>>y;
SOP(x);

1. what is ~ operator ?
2. Please explain >>> operator & its effect here on both x & y ?
3. what is value of y , after ~ .

Ranch Hand
Posts: 66
Taken from Oracle's Java Tutorial Pages

"The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension."

"The unary bitwise complement operator "~" inverts a bit pattern; it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0". For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111"."

Bartender
Posts: 4181
22
You can learn about all the operators in Java from This Tutorial. The ~ is a 'bitwise compliment' operator, which inverts the bit-value for each binary bit in a number. The >>> is a a bit shift operator that moves a 0 in to the 'sign bit' (the left bit position) essentially forcing it to be positive.

So what are the effects of these operators? The best way to see that is to convert your numbers to their binary representation then perform the operations by inverting and shifting as appropriate.