Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Converteert een int naar een string via het passende getalstelsel en het gebruikte alfabet
- string DeBruijn::convertIntToString(int getal){
- string converted;
- cout << "int "<< getal << " van het " << aantalLetters << "-talig stelsel is string ";
- // van links naar rechts getal, digit per digit overlopen
- for (int m = lengteParen-2; m > 0; m--){
- int index = 0;
- //de waarde van het kleinste getal tot deze digit mogelijk
- int grondtal = totdemacht(aantalLetters, m);
- // zolang het getal groter is dan het grondgetal -> aanpassen
- while (getal >= grondtal){
- index++;
- getal -= grondtal;
- }
- // gevonden letter op index in de tabel
- converted.append(string(1, alfabet[index]));
- }
- // laatste macht speciaal behandelen
- int index = 0;
- while (getal > 0){
- index++; getal--;
- }
- converted.append(string(1, alfabet[index]));
- cout << converted << endl;
- return converted;
- }
- //Converteert een string naar een int in het passende getalstelsel
- int DeBruijn::convertStringToInt(string combinatie){
- int totaal = 0;
- int macht = 0;
- for(int i = combinatie.length(); i > 0 ; i--){
- int waarde = charToInt[combinatie[i-1]];
- totaal += waarde * totdemacht(aantalLetters, macht);
- macht++;
- }
- cout << "string " <<combinatie << " van het " << aantalLetters << "-talig stelsel is int " << totaal << endl;
- return totaal;
- }
- int DeBruijn::totdemacht(int getal, int macht){
- int totaal =1;
- for (int i = 0; i < macht; i++) totaal *= getal;
- return totaal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement