import java.io.*; class ShowNarrowing { public static void PrintBits(byte x) { int i; for (i = 7; i >= 0; i--) if ( (x & (1 << i)) != 0 ) System.out.print("1"); else System.out.print("0"); } public static void PrintBits(short x) { int i; for (i = 15; i >= 0; i--) if ( (x & (1 << i)) != 0 ) System.out.print("1"); else System.out.print("0"); } 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) throws IOException { BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); byte b; short s; int i; System.out.print ("Enter **int** integer i: "); i = Integer.parseInt(stdin.readLine()); System.out.println ("... assigning byte i to short s and byte b...."); s = (short) i; b = (byte) i; System.out.print("i = " + i + "... 2's complement repr = "); PrintBits(i); System.out.println(); System.out.print("s = " + s + "... 2's complement repr = "); PrintBits(s); System.out.println(); System.out.print("b = " + b + "... 2's complement repr = "); PrintBits(b); System.out.println(); System.out.println("=============================================\n"); } }