• Post Reply Bookmark Topic Watch Topic
  • New Topic
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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

>>> Operator

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
Can anybody explain me how value of x is changed to positive.
int x = -1; x = x >>> 5;
Thanks
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tanveer Awan:
Take the -1 2's Complement.
1) 00000000 00000000 00000000 00000001
2) invert 11111111 11111111 11111111 11111110
3) add 1 +1
11111111 11111111 11111111 11111111
-1 in 2's Complement :- 11111111 11111111 11111111 11111111
Now >>> (UnSigned RightShif) will insert 5 zeros at the left most position
So ----------> 00000111 11111111 11111111 11111111
That will be : 134217727
Hope this Helps.
Siva.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic