1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
miss Akunina [59]
1 year ago
9

use c , c, java or python (any one) programming language for the following programming exercises. do not call built-in library f

unctions that accomplish these tasks automatically. (examples are sprintf and sscanf from the standard c library.) write a function that receives a string containing a 32-bit hexadecimal integer. the function must return the decimal integer value of the hexadecimal integer. demonstrate your function with a driver program.
Computers and Technology
1 answer:
Karo-lina-s [1.5K]1 year ago
3 0

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

You might be interested in
In theory, a hacker with a small but powerful directional antenna could access a wireless network from more than one mile away.
Svetradugi [14.3K]
100 miles i assume since the avarge antanna cover 5-50 miles
3 0
2 years ago
Why is it important to explore an Integrated
dezoksy [38]

Answer:

The answer to this question is given below in the explanation section. The correct answer is B.

Explanation:

The purpose behind to explore an integrated development environment is to learn more about the features of the environment.

So the correct answer is B.

For example, you can use visual studio to build asp.net application using c#, then you need to explore what features visual studio offering to you.

However, other options are incorrect. Because, you can learn more about syntax, error handling, and abstraction in the programming language, not in the IDE.

6 0
2 years ago
What is one invention that has had an impact on the way you live?<br><br>Write an essay
xz_007 [3.2K]
My phone duhhh. If I hadn’t had a phone I wouldn’t be able to send streaks...
8 0
3 years ago
Read 2 more answers
Given an list of N integers, Insertion Sort will, for each element in the list starting from the second element: Compare the ele
Elena L [17]

Answer:

def insSort(arr):

ct=0;

for i in range(1, len(arr)):

key = arr[i]

j = i-1

while j >=0 and key < arr[j] :

arr[j+1] = arr[j]

j -= 1

ct=ct+1;

arr[j+1] = key

return arr,ct;

print(insSort([2,1]))

Output of the program is also attached.

8 0
3 years ago
Select the correct answer from each drop-down menu. Computer memory stores data as a series of 0s and 1s. In computer memory, re
attashe74 [19]

Answer:

Zero (0); one (1).

Explanation:

Boolean logic refers to a theory of mathematics developed by the prominent British mathematician, called George Boole. In Boolean logic, all variables are either true or false and are denoted by the number "1" or "0" respectively; True = 1 or False = 0.

The memory of a computer generally stores data as a series of 0s and 1s. In computer memory, zero (0) represents the absence of an electric signal i.e OFF and one (1) represents the presence of an electric signal i.e ON.

4 0
3 years ago
Other questions:
  • A_____refers to the entire Excel file
    14·1 answer
  • Describe the benefits and drawback of using virtualisation on a single machine and also in a cluster environment
    10·1 answer
  • Service that connects on-premises software appliances with cloud based storage is ______
    10·1 answer
  • Explain what is meant by information technology (IT). Explain what is meant by information systems (IS). Why is it important to
    7·1 answer
  • One of the most common uses of spreadsheet are
    12·1 answer
  • Which of the following is NOT a valid name for a function?
    5·1 answer
  • Indicate whether the statement is true or false. ____ 1. Autoglobal array elements are referred to with an index number. ____ 2.
    9·1 answer
  • If a file you are opening for appending does not exist, the operating system will detect the missing file and terminate the oper
    14·1 answer
  • I love the brainly update guys! :)
    5·2 answers
  • What could happen if I break copyright law in the future​
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!