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

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!