Versions Compared

Key

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

...

This compliant solution uses the double type, instead of float, as a safer means of handling the widening primitive conversion resulting from integer promotion.:

Code Block
bgColor#ccccff
class Test{
  public static void main(String[] args){
    int big = 1999999999;
    double one = 1.0d; // Double instead of float
    System.out.println(big * one);
  }
}

...

This compliant solution masks off the upper 24 bits of the byte array element to achieve the intended result.:

Code Block
bgColor#ccccff
byte[] b = new byte[4];
...
int result = 0;
for (int i = 0; i < 4; i++) {
  result = (result << 8) | (b[i] & 0xff);
} 

...