Skip to content

Remove redundant '& 0xFF' from int-to-byte cast

Сергей Цыпанов requested to merge stsypanov/asm:bitwise into master

When we do

byte b1 = (byte) (value & 0xFF);

we keep from int only 1 lower byte and exactly the same can be achieved with plain cast. See the test below:

public class Main {
  public static void main(String[] args) throws Exception {
    IntStream.range(Integer.MIN_VALUE, Integer.MAX_VALUE).forEach(value -> {
      byte b1 = (byte) (value & 0xFF);
      byte b2 = (byte) value;
      if (b1 != b2) {
        throw new RuntimeException("" + value);
      }
    });
}

Merge request reports