Implement a program in C/C++ to convert integers between any two arbitrary bases, and add 2 numbers
of the same arbitrary base.
Support any base between 3 and 36, using the digit symbols
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
Humans typically enter numbers into machines as strings of characters representing a value in some
positional number system. Common bases are 2, 10, and 16. In theory, any base could be used, and
these unusual bases do occur occasionally in computer science and in Klingon. Kapla!
More generally, many strings, other symbol sequences, and also more abstract sequences, can be
interpreted as positional numbers. One example is the 3-letter sequences in DNA that code for particular
amino acids. Perhaps the inhabitants of some distant planet ‘count’ in colors!
Requirements:
Download the “bases.cpp” template. Complete and test the functions declared in the template.
1) Convert a string representation of a positional number in some arbitrary base to an integer.
// input s, base, return long
long my_atoi(char * s, int base)
2) Convert an int to a string representation of a positional number in some arbitrary base.
// input n, base, return sOut by reference
void my_itoa(long n, char * sOut, int base)
4) Convert an int to a DNA 3-codon sequence.
// input i, return codon by reference
void itoDNAcodon(char * codon, int i)
5) Add 2 numbers of any arbitrary base. Your addition algorithm MUST perform the addition IN THE BASE.
By which I mean, process the numbers as strings, iterating through the digits of each string, add num1[i] +
num2[i] + carry = sum[i], loop. Do NOT use atoi(), my_atoi(), etc, to convert the strings to integers.
Instead, process each character individually.
// input s1, s2, base, return sum
void addInBase(char s1[], char s2[], char sum[], int base)
Testing:
Thoroughly test with a variety of input values to demonstrate that your program works.
Turn In:
1) Source Code.
2) Output
Sample Output
16 base 36 is 42 base 10
42 base 10 is 39 base 11
ACT in DNA is 33 base 10
33 base 10 is ACT in DNA
…etc…do a few more to prove it works
ABBA base 16 + ACDC base 16 = 15896 base 16
…etc…do a few more to prove it works
Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount