• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

left shift operator

 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

whats the output and how is it calculated..??
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The output is 0, how it is calculated I dunno!
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The result of 8 << -1 will be O.
According to JLS, the last five bits of the right hand operand is considered for shift and then mask this value with 0x1f.
Calculating -1
1 ---------------------------------00001
one's complement-------------------11110
Adding 1--------------------------- 1
Twos complment is------------------11111
Now mask this value with 0x1f,which means 11111
11111
11111
--------
11111
----------
So we get the value as 31, so that means 8 needs to be shifted left by 31.
00000000 0000000 00000000 00001000
SO when we will shift it by 31 places, we will only be left with Zeroes..

Hope this helps.
Regards,
Harjinder
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But what about -1>>8.
Is there any way, please let me know
 
shiva thadakamadla
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But what about -1>>8.
Is there any way, please let me know
 
reply
    Bookmark Topic Watch Topic
  • New Topic