This compliant solution assumes that the unsigned integer has 32 bits. It reads in an unsigned integer value into an array of four bytes. The bytes are left shifted by the appropriate amount and OR'ed together. However, when the bytes are shifted they are promoted to {{int}} (the last byte is promoted to an {{int}} to compute the bitwise-OR). If the byte is negative, then all the left-mosthigher order bits of the resulting {{int}} will be set due to sign extension, and these have to be masked off. Finally, the whole {{int}} expression may be negative when it is promoted to the {{long}} {{result}} and, again, the higher left-mostorder bits have to be masked off. (cf. \[[Harold 97|AA. Java References#Harold 97]\] but the code there is wrong.incorrect) |