• 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

Dans Question -Operators

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

What is the result of attempting to compile and run the program?
Answer is 31,0.
Can anyone explain me the exact pen and paper calculation for the same.As I feel the calculation will be pretty hectic, considering that int is 32 bit.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hope this helps,
Henry
[ May 18, 2005: Message edited by: Henry Wong ]
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Note: for shifting, only the lowest five bits are used



And in case of long, use lowest six bits.
 
shetal bansal
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanxs a lot for the nice explanation!!
Just wanted to confirm one thing, that in case of integers, for shifting lowest 5 bits are used and in case of shifting of long, lowest 6 bits are used?
Are these the only two cases?Meaning no other special cases where the no. of bits vary?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Those are the only possiblities.All other types byte,short,char are promoted to int.

The type promotion is applied to both the operators separately.
The resulting type and number of bits shifted depends only on the type of the L.H.S operator.
Hope this helps....
-vinu.
[ May 19, 2005: Message edited by: vinuharan haran ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic