...
| Code Block | ||
|---|---|---|
| ||
int x = 50; x += (x << 2) + 1; |
Noncompliant Code Example (Left Shift)
This noncompliant code example segrates arithmetic and bitwise operators by variables. The x variable participates only in bitwise operations, and y participates only in arithmetic operations.
| Code Block | ||
|---|---|---|
| ||
int x = 50;
int y = x << 2;
x += y + 1;
|
This example is noncompliant because the actual data receives both bitwise and arithmetic operations performed on it, even though they are segregated into different variables.
Compliant Solution (Left Shift)
...
| Code Block | ||
|---|---|---|
| ||
byte[] b = new byte[] {-1, -1, -1, -1};
int result = 0;
for (int i = 0; i < 4; i++) {
result = ((result << 8) | (b[i] & 0xff));
}
|
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="9f35e0f5eae547dd-babe2332-41514712-91109d0b-455d63f7f52f4c25807830e9"><ac:plain-text-body><![CDATA[ | [[Steele 1977 | AA. Bibliography#Steele 1977]] | ]]></ac:plain-text-body></ac:structured-macro> |
...