aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes int , byte , long ,short , char ,  + shifting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "int , byte , long ,short , char ,  + shifting " Watch "int , byte , long ,short , char ,  + shifting " New topic
Author

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

sonu sharma
Greenhorn

Joined: May 17, 2003
Posts: 24
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

Joined: Aug 26, 2001
Posts: 7610
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.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Brian Joseph
Ranch Hand

Joined: May 16, 2003
Posts: 160
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

Joined: May 17, 2003
Posts: 24
thanx Brian and Valentin i looked thru some material and 'm clearer abt it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int , byte , long ,short , char , + shifting
 
Similar Threads
bit shift questions
Bit Shifting with negative numbers
Work in MNCs
developers in non ITsectors
Regarding Bit Shifting