3

The below one prints values -2147483648 and -2147483648

int a = Integer.MIN_VALUE;

int b = -a;

System.out.println( a+ "   "+b);

Could someone explain what the other value is not +ve? It is because of boundary issues?

Snehal Masne
  • 3,403
  • 3
  • 31
  • 51
  • Integer.MAX_VALUE equals to 2147483647 (or: 2^31-1) – Joachim Rohde Sep 08 '14 at 11:29
  • High sign bit 0 is for pure positive numbers and zero. High sign bit 1 is for negative numbers, so there is one negative number more than pure positive numbers. MIN_VALUE == MAX_VALUE + 1 so to say. And -n = ~n + 1 (flip bits, add one). – Joop Eggen Sep 08 '14 at 11:34

0 Answers0