Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++.I'm trying to do a substract and a divison function that substracts two binary strings numbers. The calcul has to be direct from string to

C++.I'm trying to do a substract and a divison function that substracts two binary strings numbers. The calcul has to be direct from string to string(no convertion allowed)

This is how my functions are looking already but they don't quite work. How can I make them work, or has anyone simpler functions?

string SoustracBin(string bin1, string bin2){ string sous; string b; b='1'; if(bin1==bin2){ sous='0'; ; } else { while (bin2.size() != bin1.size()) { bin2 = '0' + bin2; } for (char & i : bin2) { if (i == '0') { i = '1'; } else if (i == '1') { i = '0'; } } bin2 = SumBin(bin2, b); sous = SumBin(bin1, bin2); int i = 0; while (sous.size() > bin1.size()) { //resize du num binaire au resultat juste. i++; sous.erase(0, i); } i=1; while(sous[0]=='0') { // si il a un 0 au debut du binare, ca supprime sous.erase(0, i); } } return sous; } string divBin(string bin1, strig bin2){ string result=""; string remainder = ""; for (int i = bin1.size(); i>=0 ; i--) { remainder += bin1[i]; if (remainder.size() < bin2.size()) { result += "0"; continue; } else if (remainder.size() >= bin2.size()) { result += "1"; remainder = SoustracBin(remainder, bin2); } else result+='0'; } cout< 

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 1 Lnai 9851

Authors: Paolo Frasconi ,Niels Landwehr ,Giuseppe Manco ,Jilles Vreeken

1st Edition

3319461273, 978-3319461274

More Books

Students also viewed these Databases questions

Question

In what order would the financial statements be prepared? Why?

Answered: 1 week ago