Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Got such an amazing answer last time, I'll try again and go for two! I'm trying to write a series of functions in C++ to

Got such an amazing answer last time, I'll try again and go for two!

I'm trying to write a series of functions in C++ to convert between different value types, binary, decimal, hex.

I am allowed to only use the Libraries;

#include #include //for the pow function #include

This particular Function receives a Hexadecimal value as a string, then processing the string and converting it to a decimal value, then finally returning that decimal.

The function call looks like so:

cout

The Function as I have so far is returning the wrong values. Something's not right and I believe it is a variable size issue that I had with two functions before it, and its use of the pow function casting a double onto an int. But I'm not seeing the work around yet. Any insight is highly appeaciated.

The function:

image text in transcribed //Converts any UNsigned hexadecimal number to decimal

int hex_to_dec(string s) { int dec = 0; int length = s.size(); for (int i = 0; i = 'A') dec += pow(16, length - i - length) * (s[i] - 55); else dec += pow(16, length - i - length) * (s[i] - 48); } return dec; }

Qint hex_to_dec (string s) { int dec = int length s.size(); for (int i 0; i = 'A') dec += pow(16, length i - length) (s[il. 55); else dec += pow(16, length i length) * (s[il - 48); } return dec; CS H:\SPRING 2021\ASSEMBLY_LANG\Programs\Project21Debug Project2.exe * 0 4ABC hexadecimal = 10 decimal F5 hexadecimal = 15 decimal 1234 hexadecimal = 1 decimal FDECB hexadecimal = 15 decimal

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 Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

What is crowdfunding? Have you used any crowdfunding apps recently?

Answered: 1 week ago