Question: 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

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!