Is there any other solution?
I think the loop does not add βclarityβ to this code. The real problem is that you duplicate code like (valueAsBytes [i] and 0xFF) four times. If at all, you can do something like:
int asInt = maskIndexedValueAndShiftBy(3, 0) | maskIndexedValueAndShiftBy(2, 8) | ...
with
private final int maskIndexedValueAndShiftBy(int index, int shifter) { return (valueAsBytes[index] & 0xFF) << shifter;
The cycle simply complicates the understanding of all the calculations.
source share