Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Bitwise operation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Java ==== {{anchor|Shifts in Java}} In [[Java (programming language)|Java]], all integer types are signed, so the "<code><<</code>" and "<code>>></code>" operators perform arithmetic shifts. Java adds the operator "<code>>>></code>" to perform logical right shifts, but since the logical and arithmetic left-shift operations are identical for signed integer, there is no "<code><<<</code>" operator in Java. More details of Java shift operators:<ref>The Java Language Specification, section [http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.19 15.19. Shift Operators]</ref> * The operators <code><<</code> (left shift), <code>>></code> (signed right shift), and <code>>>></code> (unsigned right shift) are called the ''shift operators''. * The type of the shift expression is the promoted type of the left-hand operand. For example, <code>aByte >>> 2</code> is equivalent to {{code|2=java|((int) aByte) >>> 2}}. * If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & with the mask value 0x1f (0b11111).<ref name="jls15.22.1">{{cite web|url=http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.22.1|title=Chapter 15. Expressions|website=oracle.com}}</ref> The shift distance actually used is therefore always in the range 0 to 31, inclusive. * If the promoted type of the left-hand operand is long, then only the six lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & with the mask value 0x3f (0b111111).<ref name="jls15.22.1"/> The shift distance actually used is therefore always in the range 0 to 63, inclusive. * The value of {{code|n >>> s}} is ''n'' right-shifted ''s'' bit positions with zero-extension. * In bit and shift operations, the type <code>''byte''</code> is implicitly converted to <code>''int''</code>. If the byte value is negative, the highest bit is one, then ones are used to fill up the extra bytes in the int. So {{code|1=byte b1 = -5; int i = b1 {{!}} 0x0200;|2=java}} will result in {{code|1=i == -5}}.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)