1 <p> Adds a byte value and a value which is known to the 8 lower bits clear.
2 Values loaded from a byte array are sign extended to 32 bits
3 before any any bitwise operations are performed on the value.
4 Thus, if <code>b[0]</code> contains the value <code>0xff</code>, and
5 <code>x</code> is initially 0, then the code
6 <code>((x << 8) + b[0])</code> will sign extend <code>0xff</code>
7 to get <code>0xffffffff</code>, and thus give the value
8 <code>0xffffffff</code> as the result.
11 <p>In particular, the following code for packing a byte array into an int is badly wrong: </p>
14 for(int i = 0; i < 4; i++)
15 result = ((result << 8) + b[i]);
18 <p>The following idiom will work instead: </p>
21 for(int i = 0; i < 4; i++)
22 result = ((result << 8) + (b[i] & 0xff));