import java.util.Scanner; public class IntAddShow { public static void PrintBits(int x) { int i; for (i = 31; i >= 0; i--) if ( (x & (1 << i)) != 0 ) System.out.print("1"); else System.out.print("0"); } public static void main(String[] arg) { Scanner stdin = new Scanner( System.in ); int a, b, c; while (true) { System.out.print ("Enter a: "); a = (int) stdin.nextInt(); System.out.print("a = " + a + " ===> 2's complement repr = "); PrintBits(a); System.out.println("\n"); System.out.print ("Enter b: "); b = (int) stdin.nextInt(); System.out.print("b = " + b + " ===> 2's complement repr = "); PrintBits(b); System.out.println("\n"); c = (int) (a+b); System.out.println("The sum is " + c); System.out.println(); System.out.print("c = " + c + " ===> 2's complement repr = "); PrintBits(c); System.out.println("\n"); System.out.println("=============================================\n"); } } }