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
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:
//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 decimalStep 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