# Write a program (in java) that takes two binary strings and returns three binary strings. These three strings…

Write a program (in java) that takes two binary strings and returns three binary strings. These three strings represent the following binary operations between the input strings: AND, OR, XOR (make sure it works for strings of different length)

Here are two examples:

Don't use plagiarized sources. Get Your Custom Essay on
Write a program (in java) that takes two binary strings and returns three binary strings. These three strings…
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!

Input:

1001

1101

Output:

AND:     1001

OR:         1101

XOR:      0100

Input:

101101

1001

Output:

AND:     1001

OR:         101101

XOR:      100100

Hi,

The desired operations are already present in java, here is a list of all the operators avaiable in java.

```Operator    Name         Example     Result  Description
a & b       and          3 & 5       1       1 if both bits are 1.
a | b       or           3 | 5       7       1 if either bit is 1.
a ^ b       xor          3 ^ 5       6       1 if both bits are different.
~a          not          ~3          -4      Inverts the bits.
```

So, we can use this to get the required output, the only challenge being, we have to deal with strings, for that too we have the Integer class in java which can convert string to int, here is the complete solution.

import java.util.*;
import java.lang.*;
import java.io.*;

class Test
{
public static void main (String[] args) throws java.lang.Exception
{
String s1 = “101101”;
String s2 = “1001”;

//    INTEGER.PARSEINT(S,2) CONVERTS STRING S TO INTEGER
Integer xor=Integer.parseInt(s1, 2) ^ Integer.parseInt(s2, 2); // ^ IS FOR XOR
Integer or=Integer.parseInt(s1, 2) | Integer.parseInt(s2, 2);
Integer and=Integer.parseInt(s1, 2) & Integer.parseInt(s2, 2);

// INTEGER.toBinaryString DOES THE OPPOSITE OF WHAT WE DID ABOVE
System.out.println(“XOR:”+Integer.toBinaryString(xor));
System.out.println(“OR:”+Integer.toBinaryString(or));
System.out.println(“AND:”+Integer.toBinaryString(and));
}
}

Hope this was helpful let me know if you have any questions.

Hi,

The desired operations are already present in java, here is a list of all the operators avaiable in java.

```Operator    Name         Example     Result  Description
a & b       and          3 & 5       1       1 if both bits are 1.
a | b       or           3 | 5       7       1 if either bit is 1.
a ^ b       xor          3 ^ 5       6       1 if both bits are different.
~a          not          ~3          -4      Inverts the bits.
```

So, we can use this to get the required output, the only challenge being, we have to deal with strings, for that too we have the Integer class in java which can convert string to int, here is the complete solution.

import java.util.*;
import java.lang.*;
import java.io.*;

class Test
{
public static void main (String[] args) throws java.lang.Exception
{
String s1 = “101101”;
String s2 = “1001”;

//    INTEGER.PARSEINT(S,2) CONVERTS STRING S TO INTEGER
Integer xor=Integer.parseInt(s1, 2) ^ Integer.parseInt(s2, 2); // ^ IS FOR XOR
Integer or=Integer.parseInt(s1, 2) | Integer.parseInt(s2, 2);
Integer and=Integer.parseInt(s1, 2) & Integer.parseInt(s2, 2);

// INTEGER.toBinaryString DOES THE OPPOSITE OF WHAT WE DID ABOVE
System.out.println(“XOR:”+Integer.toBinaryString(xor));
System.out.println(“OR:”+Integer.toBinaryString(or));
System.out.println(“AND:”+Integer.toBinaryString(and));
}
}

Hope this was helpful let me know if you have any questions.

Order NOW For a 10% Discount!
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

## Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.