...
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 | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
byte[] b = new byte[4];
...
int result = 0;
for (int i = 0; i < 4; i++) {
result = (result << 8) | (b[i] & 0xff);
} |
...