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

Got such an amazing answer last time, I'll try again and go //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

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!