# Help me for the insertion of binary function in my add function

 Ed Gon · December 3, 2014 Here is my code, I need the to insert the process where the inputed number converts to binary digit and those numbers will be add in binary form then converts back to decimal as a result. PLEASE HELP~=======#include #include #include using namespace std;int main(){ string cmd; long long ax = 0; bool error = false; cout << "Type in command (type \"HELP\" to see all commands): " <"; getline(cin, cmd);//catches the data if (cmd.find("ADD") == 0){ if (cmd.find(" ") == strlen("ADD")){ string x = cmd.substr(strlen("ADD "), cmd.length()-(cmd.length() - cmd.find(",") + strlen("ADD ")));//store the value of x string y = cmd.substr(cmd.find(",") + 1);//store the value of y ax = atoi(x.c_str()) + atoi(y.c_str()); //calculates the result } else{ error = true; } } else if (cmd.find("PRT AX") == 0 && cmd.length() == strlen("PRT AX")){//Triggers the PRT AX cout << ">AX = " << ax << endl;//Prints the result } else if (cmd.find("HELP") == 0 && cmd.length() == strlen("HELP")){//Triggers the HELP cout << ">" << endl; cout << ">ADD x,y add x and y and save the result in AX" << endl; cout << ">PRT AX display the value of AX" << endl; cout << ">EXIT exit the application" << endl; cout << ">" << endl; } else if (cmd.find("EXIT") == 0 && cmd.length() == strlen("EXIT")){//Triggers the EXIT break; } else{ error = true; } if (error){ cout << ">Error: Unknown command!" << endl; } }}

## Replies

- page 5

 Ed Gon · December 4, 2014 @krootushas gesuyea i know, but I am making a virtual machine(for my course project,so yea) on how computer understands. which its a hassle. Ed Gon · December 4, 2014 @Franzmy code does:if I input ADD 4,3 the 4,3 is been add 4+3 but its not been shown yet unless you input PRT AX.thus my problem now is to convert those decimal digits into binary which is the 0100 (4) and 0011 (3).then add those binary digits in binary form then the result must be converted back to decimal form. if I input PRT AX the decimal form should appear.I hope you can help Franz Schmidt · December 3, 2014 Could you please give an example what your programm does?

## C++

130,868 followers