You are on page 1of 2

import java.io.*; class binary { public static void main(String args[ ])throws IOException { DataInputStream d = new DataInputStream(System.

in); int x,y; System.out.println("Enter 2 decimal nos."); x = Integer.parseInt(d.readLine( )); y = Integer.parseInt(d.readLine( )); int sum = x+y; int p =0,p1 = 0,p2 = 0; int a[ ] = new int[10]; int b[ ] = new int[10]; int[c] = new int[10]; while(x != 0) { a[p] = x % 2; p++; x = x / 2; } System.out.print("Binary1 ="); for(int i = p-1; i >= 0; i--) { System.out.print(a[i]); } System.out.println( ); System.out.print("Binary2 ="); while(y != 0) { b[p1] = y % 2; p1++; y = y / 2; } for(int j = p1-1; j >= 0; j--) { System.out.print(b[j]); } System.out.println( ); System.out.print("Sum =");

while(sum != 0) { c[p2] = sum % 2; p2++; sum = sum / 2; } for(int k = p2-1; k >= 0; k--) { System.out.print(c[k]); } } } OUTPUT Enter 2 decimal nos. 14 10 Binary1 = 1110 Binary2 = 1010 Sum = 11000

You might also like