Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program to convert a 4 digit hexadecimal number into decimal. The user should be instructed to enter a 4-digit hexadecimal number. The corresponding

Write a program to convert a 4 digit hexadecimal number into decimal. The user should be instructed to enter a 4-digit hexadecimal number. The corresponding decimal number (0 to 65,535) should be output. Note that the place values for a 4-digit hexadecimal number from left to right are 4096, 256, then 16, then 1. You must input the Hexadecimal number as a String, then use the charAt(N) method to compare each individual character to 'A', 'B', 'C', 'D', 'E', 'F' and '0' through '9', and add the value of the digit times the corresponding place value to the total. For example, 1A3016 = 1*4096+10*256+3*16+0*1 = 670410

First, prompt for and input a String of four characters.

If the input is not four characters, print out an appropriate message and exit.

Use if statements, each meaning something like "If the second character is equal to 'A', the value of the second digit is 256 * 10". If any character is not '0'-'9' or 'A'-'F', print out an appropriate message and exit.

In order to compare each character of the input String to a char, use ==, and be sure to use single quotes rather than double quotes.

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

ISBN: 0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

2. Identify issues/causes for the apparent conflict.

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago