Question: Binary Calculator Design and implement a GUI based application to perform asa binary calculator which cando binary addition, subtraction, multiplication, division (forpositive numbers, negative numbers,

Binary Calculator

Design and implement a GUI based application to perform asa binary calculator which cando binary addition, subtraction, multiplication, division (forpositive numbers, negative numbers, and zero). Integer division isused, that is, division result is also an integer. Attached is aclass which provides methods to convert decimal to binary andbinary to decimal.

You calculator should be able to do continuous calculations suchas

the input is 110+10-1*10=+1=, the result should be 1111(continuous calculation just executes from left to right, nooperator precedence needs to be considered)

If your calculator cannot do continuous calculations, at leastit should be able to do calculations like this

110+10=-1=*10=+1=, the result should be 1111.

/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author aic */public class BinaryDecimal {        //Convert from Binary number (String) to integer    public static int BinaryToDecimal(String bin)    {        int flag=0; //0 positive number 1 negative         flag = (bin.charAt(0) != '-' ? 0:1);        if (bin.charAt(0) == '+' || bin.charAt(0) == '-')            bin = bin.substring(1);        int decimal = 0;        int digit;        for (int i=bin.length()-1;i>=0;i--)        {            if (bin.charAt(i) == '0')                digit = 0;            else if (bin.charAt(i) == '1')                digit = 1;            else            {                System.out.println("Invalid input");                return -1;            }            decimal += digit*Math.pow(2.0,bin.length()-1-i);        }        if (flag == 1)            return -decimal;        return decimal;    }        //Convert from integer to Binary number    public static String DecimalToBinary(int decimal)    {        String bin = "";        String result = "";        if (decimal<0)        {            result += "-";            decimal = 0-decimal;        }        if (decimal == 0)        {            result = "0";            return result;        }        while (decimal/2 != 0)        {            bin += (decimal%2==1)? "1":"0";            decimal /= 2;        }        bin += "1";               for (int i=bin.length()-1;i>=0;i--)            result += bin.charAt(i);        return result;    }}

Step by Step Solution

3.44 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To design and implement a GUI based binary calculator application that can perform binary addition s... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!