Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this exercise, youll write a binary to text translator! As weve seen, every character can be represented by a string of8 bits, or a

In this exercise, you’ll write a binary to text translator!

As we’ve seen, every character can be represented by a string of8 bits, or a byte. For example, the binary string010000012 has the decimal value of 6510,which maps to the character ‘A’.

We can easily go from an int value between 0 and 255 to a charvalue using casting.
For example, the following code:

int decimalValue = 65;char charValue = (char) decimalValue;System.out.println(decimalValue + " --> " + charValue);

Will print out

65 --> A

Using your binaryToDecimal method that you wroteearlier, write a method binaryToText that takes a Stringof bits, converts every 8 bits into the corresponding char,and returns a String representing the translated text.

For example:

binaryToText("0100100001001001");

Should return:

"HI"

To see why, let’s examine this binary String:

"0100100001001001"Is made of 16 bitsThe first 8 bits are "01001000"binaryToDecimal("01001000") returns 72(char) 72 equals 'H'The next 8 bits are "01001001"binaryToDecimal("01001001") returns 73(char) 73 equals 'I'The resulting String is "HI"

You may assume that binaryToText will only be passedbinary Strings that are made up of multiples of 8 bits.

public class BinaryConversion extends ConsoleProgram
{
public void run()
{
// Write some of your own test codehere!
}

public String binaryToText(String binary)
{
// Write your code here!
}

public int binaryToDecimal(String binaryString)
{
// Copy over your binaryToDecimalmethod here
// It will be useful when writing yourbinaryToText method
}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

More Books

Students also viewed these Programming questions