The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Shift Operators Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Shift Operators" Watch "Shift Operators" New topic
Author

Shift Operators

Basu Patel
Ranch Hand

Joined: May 28, 2000
Posts: 60
Can anyone explain me the left shift operator?
What i understand is that in the binay form the numbers are eleminated from the left side and more zeros are added from the right side. Is this correct for the left shift and vice versa for the right shift,except that the previous numbers are added from the left side and dropped from the right side depending on the shift value.
Thanx


<BR>Contact Me<BR> <A HREF="mailto:basu_patel@usa.net" rel="nofollow">basu_patel@usa.net</A> <P>
Sunita Vontel
Ranch Hand

Joined: Aug 28, 2000
Posts: 72
Hi Basu
For right shift the higher bit(the leftmost bit) takes precendence.If for a positive number the left side will be filled with zeros if its a negative number it will be filled with 1.
for unsigned right shift irrespective of the sign zeros are filled.
Correct me if I am wrong
chetan nain
Ranch Hand

Joined: Jun 21, 2000
Posts: 159
basu,
left shift <<<br /> example: decimal 20<br /> 00000000 00000000 00000000 00010100<br /> after <<2,<br /> 00000000 00000000 00000000 01010000<br /> which is decimal 80(you may regard each left shift as<br /> multiplication by 2. in above ex, <<2, thus, mult by 4)<br /> in case of a 1 bit at rightmost, still 0's will fill in<br /> right shift: 2 types<br /> 1. signed right shift: >><br /> 10000000 00000000 00000000 00000000 >>1 will give<br /> 11000000 00000000 00000000 00000000 <br /> in case of 0 in left most bit, 0 will be filled in<br /> 2. unsigned right shift: >>>
10000000 00000000 00000000 00000000 >>1 will give
01000000 00000000 00000000 00000000
irrespective of 1 or 0 at leftmost bit, always 0 will
fill in

HTH
chetan
Basu Patel
Ranch Hand

Joined: May 28, 2000
Posts: 60
Thanx Chetan and Sunita, I appreciate your time.
Basu
 
IntelliJ Java IDE
 
subject: Shift Operators
 
Threads others viewed
RightShift Operator....
Shift Operators Explanation
canonical path...
Shifting (to Sonir... or others if needed)
Reg. >>
MyEclipse, The Clear Choice