• 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

shifting the integer by negative number

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
8<<-1 is 0.Can anybody explain the logic behaind this?
Veena
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
shift-value << shift-distance
If the type of the shift-value is int, only the five lowest-order bits are used as the shift-distance.
8 << -1 means shift the value 8 to the left 31 bit positions,
because the five lowest-orders bits of -1 are binary 11111 == decimal 31.
8 << 32 means shift the value 8 to the left 0 bit positions,
because the five lowest-order bits of 32 are binary 00000.
If the type of the shift-value is long, only the six lowest-order bits are used as the shift-distance.
[ September 07, 2003: Message edited by: Marlene Miller ]
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much marlene.
 
reply
    Bookmark Topic Watch Topic
  • New Topic