Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ substring to decimal How do you convert a substring to a decimal. I know there is stoi but it doesnt seem to be working.

c++ substring to decimal

How do you convert a substring to a decimal. I know there is stoi but it doesnt seem to be working. So im writting a program that decodes 32 bit machine code(00000011100011...) where the first six bits determine the type of instruction it is and if its an R type instruction then the next 5 bits determine rd, rs, and rt; basically registers and operations. I have it structed like this:

cout << "enter machine code: <

cin << machinecode;

string opcode = machinecode.substr(0, 6)

if(opcode.copmare('000000') == 0){

//call r type function

}

void rtypefunction(string mc, string oc){

count<<"type R"<

string shift = mc.substr(21,5) //starting at position 21 up to len 5

cout<

}

I essentially want shift to be printing out the decimal version of 00001, 00000, 01101 which would be 1, 0 or 13 basically any bits thrown at it. I tried having int shift = stoi(mc.substr(21,5) but nothing prints out if i insert that.

By r type, rs, rd these are related to MIPs instructions. This doesnt really matter, i just need to convert the substring im passing to shift to 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

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

Students also viewed these Databases questions