Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a Java program to convert a string corresponding to a hexadecimal number of the form 0xHHHHHH to decimal as shown in the following examples:
Write a Java program to convert a string corresponding to a hexadecimal number of the form 0xHHHHHH to decimal as shown in the following examples:
Hexadecimal conversion program
Enter a hex number in the format 0xH...H, +ve only, blank line terminates.
Input is case insensitive except for leading 0x
> 0xFf
0xFf = 255
> 0
0 is not a valid entry.
> 0x0
0x0 = 0
> 0x10
0x10 = 16
> 0xf
0xf = 15
> 0xF
0xF = 15
> 0xfFfF
0xfFfF = 65535
>
Program terminated.
Notes
1. The input string must begin with the prefix 0x.
2. The hexadecimal digits are case insensitive, i.e., f and F are both interpreted as 15.
3. Your program MUST replicate the above example, EXACTLY.
4. Your program will consist of a single class, HexConversion, and must implement a method, hex2Int() with the following signature:
int hex2Int (String input);
5. This program is similar to Assignment 1. Of the String class methods, you are only allowed to use equals(), length(), charAt() and startsWith().
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started