/**
 * @(#)multiplingIntegers.java
 *
 *
 * @author 
 * @version 1.00 2011/3/8
 *
 */

import javax.swing.*;
public class walaa {
 static int m;
   public static void main (String[] args) {
 try{int x=Integer.parseInt(JOptionPane.showInputDialog("please enter binary number "));
 int y=Integer.parseInt(JOptionPane.showInputDialog("please enter binary number "));
String s1=String.valueOf(x);
String s2=String.valueOf(y);
 if(s1.length()>s2.length())
 m=s1.length();
 else
 	m=s2.length();
//JOptionPane.showMessageDialog(null,"the max is "+max(x,y));
 //JOptionPane.showMessageDialog(null,"the xl is "+leftmost(x));
 //JOptionPane.showMessageDialog(null,"the xr is "+rightmost(x));


int output= multiply(x,y);
ToBinary(output);
 JOptionPane.showMessageDialog(null,"the output is in dicimal "+output+"\n The output in Bianry is "+ToBinary(output));
 }
 catch(NumberFormatException e)
 {System.out.print("the digets are not equal ");
 }
} 
public static  int max(int x, int y)
{String s1=String.valueOf(x);
String s2=String.valueOf(y);
	int maxX=s1.length();
	int maxY=s2.length();
  
	
	if(maxX>maxY)
		return maxX;
		else
			return maxY;
}
public static int leftmost(int x)
{String s=String.valueOf(x);
double  n=(double )s.length()/2;
int num=(int)Math.ceil(n);
String left=s.substring(0,num);

return Integer.parseInt(left);
}

public static int rightmost(int y)
{String s=String.valueOf(y);
double  n=(double)s.length()/2;
int num=(int)Math.ceil(n);

String right=s.substring(num,s.length());


return Integer.parseInt(right);
}



 public static  int multiply(int x, int y)   
 {int p1,p2,p3;
 	int n=max(x,y);
 	if(n==1) return x*y;
 	
 	{
 		
 	int xl=leftmost(x);
 	int xr=rightmost(x);
 	int yl=leftmost(y);
 	int yr=rightmost(y);
 	
  p1=multiply(xl,yl);
 	
 //JOptionPane.showMessageDialog(null,"p1 is "+p1);
 	 p2=multiply(xr,yr);
 //	JOptionPane.showMessageDialog(null,"p2 is "+p2);
 	 p3=multiply((xl+xr),(yl+yr));
//	JOptionPane.showMessageDialog(null,"p3 is "+p3+"Xl + Xr is "+(xl+xr));
 
 	}
 	if(m==3)
 	{n=2;
 	}
 	return (p1*(int )Math.pow(2,n))+((p3-p1-p2)*(int)Math.pow(2,(n/2)))+p2;
 } 
 public static StringBuffer ToBinary(int n)
    {
    		String str="";
    	try{
    	while(n>0)
    	{
    		int d=n%2;
    		n=n/2;
    		
    		str+=String.valueOf(d);
    	}}
    	 catch(NumberFormatException e)
    {
    }
    StringBuffer stb=new StringBuffer (str);
    stb.reverse();
    
    	return stb;
   
    }
}