File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dans Question -Operators

 
shetal bansal
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hope this helps,
Henry
[ May 18, 2005: Message edited by: Henry Wong ]
 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
vinuharan haran
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic