Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
public static final int MASK = 1337;
public static final int OFFSET = -1337;

public static int computeCode(int x) {
  return (x & MASK) + OFFSET;
}

Note that this solution performs bitwise operations on signed integers. Care must be exercised when doing this; see guideline "void NUM05-J. Avoid incorrect mixing of signed integers with bitwise operators" for more information.

Exceptions

EXP06-EX1EX0: Parentheses may be omitted from mathematical expressions that follow the algebraic precedence rules. For instance, consider the expression:

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c3c192501097d515-859bbc8b-44e247c7-bc688700-fc0d3fc17375b77b1a33b36a"><ac:plain-text-body><![CDATA[

[[ESA 2005

AA. Bibliography#ESA 05]]

Rule 65: Use parentheses to explicitly indicate the order of execution of numerical operators

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="3b5ce19c76a4710b-787414b4-467f4f59-b4f89348-ebb83297c92be288de7d338b"><ac:plain-text-body><![CDATA[

[[Tutorials 2008

AA. Bibliography#Tutorials 08]]

[Expressions, Statements, and Blocks

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/expressions.html]

]]></ac:plain-text-body></ac:structured-macro>

 

Operators

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5a0133b16bb387b0-8428dd5c-4e674fe9-8962bc4e-13bc23682c3a518fbc2ddb7a"><ac:plain-text-body><![CDATA[

[[Rogue 2000

AA. Bibliography#Rogue 2000]]

Rule 77: Clarify the order of operations with parentheses

]]></ac:plain-text-body></ac:structured-macro>

...