This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Bit Shift Operator Signed Left Shift 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 "Bit Shift Operator Signed Left Shift" Watch "Bit Shift Operator Signed Left Shift" New topic
Author

Bit Shift Operator Signed Left Shift

Sandy Lee
Greenhorn

Joined: Jan 18, 2001
Posts: 18
Hi! All can anyone explain how
- 5 << 29 is giving a positive number of 1610612736
Is << not a signed left shift and should therefore give a
negative number?
I am not able to manually determine th above result.
Can anyone please explain??!!
Udayan Naik
Ranch Hand

Joined: Oct 18, 2000
Posts: 135
Hi Sandy.The number -5 will be represented as 1111 1111 ...1011.After shifting to the left 29 times,the 0 will be in the MSB position.Now the number will be 0110 0000 ...0000 ;a positive number.The value will be (2 raised to 30 + 2 raised to 29) ie 1610612736.
Try doing the mathematics with paper and pencil,and u will get it.
[This message has been edited by Udayan Naik (edited January 19, 2001).]


Udayan Naik<BR>Sun Certified Programmer for the Java 2 Platform
Sandy Lee
Greenhorn

Joined: Jan 18, 2001
Posts: 18
Thanks Udayan.
I get it now.
Sandy.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bit Shift Operator Signed Left Shift
 
Similar Threads
Shift Operators
shift operators
can we apply left hift and right shift operators to double,float???
Doubts on the mock Exam
unsigned right shift operator