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 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 "shifting" Watch "shifting" New topic
Author

shifting

Nadeem Malik
Greenhorn

Joined: Nov 22, 2000
Posts: 10
hi all,
plzz try this,
(Q1)
5<<32 results 5
5<<-32 results 5
5<<33 results 10
these are ok but
plzz explain this,
5 << -33 results -2147483648 i.e the lowest boundry of int datatype.
(Q2)
plzz explain
-1 >> 1 results -1 not 0
Nasir Khan
Ranch Hand

Joined: Nov 04, 2000
Posts: 135
Hi Nadeem,
Only 5 bits of the right operand are used the reason is that an int is a 32-bit value and can only be shifted 0 through 31 times.
Now see 5 << -33
-33 divided by 32 gives -1 (i assume you know the reason)
-1 in binary is 111111111111111111111111111111111
take only 5 bits it's now 11111 and equals 31 in decimal
given question becomes 5<<31 I think you know the rest.
second question is -1>>1 and sure it'll give -1 the reason is right shift is a signed operator i.e it preserves the sign.
the bits that fill in the shifted left bits have the value of the leftmost bit(before the shift operation).
Nadeem Malik
Greenhorn

Joined: Nov 22, 2000
Posts: 10
Thanx Nasir Khan,
i am now satisfied.
Vladimir Kositsky
Ranch Hand

Joined: Nov 03, 2000
Posts: 116
hi!
i am looking for source of binary arithmetics conception and examples
higly appreciate any help in advance
Sam Wong
Ranch Hand

Joined: Dec 07, 2000
Posts: 133
Just do a search for binary addition or subtraction on one of the search engines. (Yahoo, Altavista, etc)
Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
I have some info for shift/bitwise operations on my page.
Check the tips page at
http://www.geocities.com/velmurugan_p
Hope this helps.
------------------
Velmurugan Periasamy http://www.geocities.com/velmurugan_p/


------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: shifting
 
Similar Threads
Shift
pls tell me why?
How this output is coming regarding left shift operator
question on Shifting
about >>> op.