This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

int , byte , long ,short , char , + shifting

 
sonu sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i 'm not sure about how signed and unsigned values in the primitives are stored and thus used for shifting operations could some one plz throw some light on this issue.
thanx in advance.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
byte, short, int, and long's values are signed two's complement integers.
Only char is unsigned.
When a shift operation is performed unary numeric promotion is performed on each operand separately.
If the left-hand operand is a byte, short or char, it is promoted to int. If the left-hand operand is int or long, there is no promotion.
 
Brian Joseph
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you find some material about how bytes and shorts are treated with the shift operator. Because a byte and short are promoted to an int before the operation, the results you can get from shifting a byte or short can be unexpected.
 
sonu sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx Brian and Valentin i looked thru some material and 'm clearer abt it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic