Win a copy of Rust Web Development this week in the Other Languages forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Liutauras Vilda
• Jeanne Boyarsky
Sheriffs:
• Junilu Lacar
• Rob Spoor
• Paul Clapham
Saloon Keepers:
• Tim Holloway
• Tim Moores
• Jesse Silverman
• Stephan van Hulst
• Carey Brown
Bartenders:
• Al Hobbs
• Piet Souris
• Frits Walraven

# >>> Operator

Greenhorn
Posts: 5
• Number of slices to send:
Optional 'thank-you' note:
Hello!
Can anybody explain me how value of x is changed to positive.
int x = -1; x = x >>> 5;
Thanks

Ranch Hand
Posts: 30
• Number of slices to send:
Optional 'thank-you' note:
Hello!
Can anybody explain me how value of x is changed to positive.
int x = -1; x = x >>> 5;
Thanks
You need to think in terms of binary digits now...
For Example)
integer is a numeric primitive type,
Value of int 1 in Binary is represented as
0000 0000 0000 0000 0000 0000 0000 0001
Take ones complement which is
1111 1111 1111 1111 1111 1111 1111 1110
Add 'one' to get two's compliment
1111 1111 1111 1111 1111 1111 1111 1110
1+
-----------------------------------------
1111 1111 1111 1111 1111 1111 1111 1111
So -1 is represented in binary as
1111 1111 1111 1111 1111 1111 1111 1111
x = x >>> 5;
which is,
0000 0111 1111 1111 1111 1111 1111 1111
which is a positive value 134217727
I hope i have not confused U
rgds
Venky

Ranch Hand
Posts: 75
• Number of slices to send:
Optional 'thank-you' note:
Hi Tanveer Awan:
Take the -1 2's Complement.
1) 00000000 00000000 00000000 00000001
2) invert 11111111 11111111 11111111 11111110