A function that receives a string containing a 32-bit hexadecimal integer. the function must return the decimal integer value of the hexadecimal integer.
<h3>The C++ Program</h3>
#include<iostream>
#include <cstring>
#include <string>
using namespace std;
int getDecimalForm(string);
int main() {
// string binary;
// Reads both 0 and B as int 48 while B should be
string hexadecimal = "01F12EBA";
int decimalForm;
int re = hexadecimal[0], te = hexadecimal[1];
/*cout << "Input an eight digit binary string of 1s and 0s to find the integer
value in decimal form:\n"; cin >> binary;
// Input validation
while (binary.size() != 8 || ((binary[0] != '0' && binary[0] != '1')
|| (binary[1] != '0' && binary[1] != '1') || (binary[2] != '0' && binary[2] !=
'1')
|| (binary[3] != '0' && binary[3] != '1') || (binary[4] != '0' && binary[4] !=
'1')
|| (binary[5] != '0' && binary[5] != '1') || (binary[6] != '0' && binary[6] !=
'1')
|| (binary[7] != '0' && binary[7] != '1')))
{
cout << "Input a valid eight digit binary string of only ones and zeros\n";
cin >> binary;
}*/
cout << "The 32-bit binary integer value is " << hexadecimal << endl;
cout << re << " " << te << " " << hexadecimal[0] - 55 << endl;
decimalForm = getDecimalForm(hexadecimal);
cout << endl
<< decimalForm << " is the same integer value expressed in decimal form";
}
// a function in C++ that receives a string containing a 16 - bit binary integer
int getDecimalForm(string hStr) {
int value, num = 1, total = 0, exponent = 0;
// Made adding happen starting from the right side
for (int i = (hStr.size() - 1); i >= 0; i--) {
if ('0' <= hStr[i] <= '9') {
cout << hStr[i] << " cat\n";
if (exponent != 0) {
for (int j = 0; j < exponent; j++) {
num *= 16;
}
}
value = num * (hStr[i] - 48);
}
if ('A' <= hStr[i] <= 'F') {
cout << hStr[i] << " dog\n";
if (exponent != 0) {
for (int j = 0; j < exponent; j++) {
num *= 16;
}
}
value = num * (hStr[i] - 55);
}
// Keep adding the value of the binary integer
total += value;
num = 1;
exponent++;
}
return total;
}
Read more about C++ program here:
brainly.com/question/20339175
#SPJ1