• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

doubt shift ??

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


fnrds

my doubt here is that whenever there is a shift being done ,it is promoted to int ..as here
-64 means 1100 0000
which gets promoted while shifting to int ..
and after which truncated to byte nd evaluated...right??
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srikanth,

What I understand ( and people please correct if I am wrong) is first the byte number is promoted to an integer. In this process, -64 erstwhile represented as 0xc0 would now be represented as 0xffffffc0 (in 32 bit register). Thereafter the number is shifted and the result(-4) is returned as int.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you perform a shift operation, both operands, the value to be shifted and the amount to shift it by, must be an int or a long.
{
Here in (b >>>4) b=-64 & 4 both needs to be an int or long
}
If they aren't, they are promoted (if they can be � if not, you end up with a compiler error).
{
since byte b=-64.....b is converted to int & shift operation is done then after...
}

The result of the operation is the type of the left hand operand, which will be an int or a long.
{
After shift operation the result is an int....
}

As neither of those types are assignable to a byte, It must cast it as a byte or the compiler will complain.
[ November 07, 2005: Message edited by: Purujit Saha ]
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
remember viewers: this is a 1.4 topic but NOT a 5.0 topic!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic