1 year ago

#288256

test-img

ArtemisCode7

Math.toIntExact((long) value & 0xFFFFFFFFL) integer overflow

I was shown this arbitrary piece of code and I think it serves no purpose since when I tried to run it, any time I pass in a negative number for the value to actually satisfy the if statement I get an ArithmeticException: integer overflow.

Is there any values I can actually pass into value such that the if statement is satisfied and Math.toIntExact((long)value & 0xFFFFFFFFL) doesn't throw an error?

public static void main(String args[]) {
    int value = Integer.parseInt(args[0]);
    if (value < 0){
        int result = Math.toIntExact((long)value & 0xFFFFFFFFL);
        System.out.println(value);
        System.out.println(result);
    }
}

java

integer-overflow

0 Answers

Your Answer

Accepted video resources