Defines interface of radix.c functions (do not modify) More...
Go to the source code of this file.
Functions | |
char | int2char (int radix, int value) |
int | char2int (int radix, char digit) |
void | int2str (int radix, int value) |
int | str2int (int radix) |
double | str2frac (int radix) |
This file defines the interface to a C file radix.c that you will complete.
Numbers can be reperesented in various number bases. Humans use base 10. Many times it is convenient to work in other bases. For bases with a radix greater that 10, other characters must be used to represent the "digits" of the human readable form. The characters '0' thru '9' represnt values 0 to 9. The characters 'A' to 'Z' represent values greater that 10 with 'A' representing 10, 'B' representing 11 and so on up to 'Z' representing 35. We will not wory about number bases beyond that. Thus, only '0'..'9' and 'A'..'Z' will ever be used. For convenience, the characters 'a'..'z' are also allowed, and each lower case letter represents the same as its upper case equivalent.
int char2int | ( | int | radix, |
char | digit | ||
) |
Convert a character representing a digit in the specified base to its value
radix | the radix in which you are working (2-36) |
digit | the character to convert |
char int2char | ( | int | radix, |
int | value | ||
) |
Get the character associated with a value in a specified radix
radix | the radix in which you are working (2-36) |
value | should be in range 0 to radix - 1 |
void int2str | ( | int | radix, |
int | value | ||
) |
Print the sequence of characters/digits that represents, in the specified radix, the given integer. Your program cannot use arays or strings in C (even if know about them). It should determine the characters to print out using the algorithm of repeated division. The only output function you are allowed to use is putchar()
from stdio.h
. [Hint: think recursion].
radix | the radix in which you are working (2-36) |
value | the value to print out. |
double str2frac | ( | int | radix | ) |
Convert a sequence of characters representing a fractional number in the given radix into the integer value that it represents. The only input function you are allowed to use is getchar()
from stdio.h
. This function is for extra credit
radix | the radix in which you are working (2-36) |
int str2int | ( | int | radix | ) |
Convert a sequence of characters representing a number in the given radix into the integer value that it represents. The only input function you are allowed to use is getchar()
from stdio.h
.
radix | the radix in which you are working (2-36) |