Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, for an assignment I have to make a program in Java that converts Hexadecimal values to decimal, Binary values to decimal and also convert

Hello, for an assignment I have to make a program in Java that converts Hexadecimal values to decimal, Binary values to decimal and also convert from Binary To Hexadecimal. the sample output is at the end.

This assignment is designed to get you to use loops in conjunction with the standard Java String class, the Java char type, and some arithmetic. Your program will take a hexadecimal or binary number as an input, and then print out its decimal value.

Your program must have a looping menu that prompts the user to choose between hex to decimal decoding, binary to decimal decoding, or binary to hex. Binary to hex is extra credit and is not required to be implemented.

Your program must use methods. The following method signatures must be matched, and implemented and used properly. They must not print anything out.

public static long hexStringDecode(String hex) //Decode whole hex string

public static short hexCharDecode(char hexChar) //Decode single character

public static long binaryStringDecode(String bin) //Decode binary string

public static String binaryToHex(String bin) //Optional

Sample Output:

Choose an option:

1. Decode a hex string.

2. Decode a binary string.

3. Convert binary to hex.

4. Quit.

1

Please enter the hex string:

0x4321

Result: 17185

Choose an option:

1. Decode a hex string.

2. Decode a binary string.

3. Convert binary to hex.

4. Quit.

1

Please enter the hex string:

0xFFFFFFFF

Result: 4294967295

Choose an option:

1. Decode a hex string.

2. Decode a binary string.

3. Convert binary to hex.

4. Quit.

2

Please enter the binary string:

1010

Result: 10

Choose an option:

1. Decode a hex string.

2. Decode a binary string.

3. Convert binary to hex.

4. Quit.

2

Please enter the binary string:

11111111

Result: 255

Choose an option:

1. Decode a hex string.

2. Decode a binary string.

3. Convert binary to hex.

4. Quit.

3

Please enter the binary string:

111110000001

Result: F81

Choose an option:

1. Decode a hex string.

2. Decode a binary string.

3. Convert binary to hex.

4. Quit.

4

Quitting program.

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

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions

Question

Find 1!, 2!, 4!, and 6!.

Answered: 1 week ago