Functions
radix.h File Reference

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)
 

Detailed Description

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.

Author
Fritz Sieker, modified by Sanjay Rajopadhye

Function Documentation

int char2int ( int  radix,
char  digit 
)

Convert a character representing a digit in the specified base to its value

Parameters
radixthe radix in which you are working (2-36)
digitthe character to convert
Returns
-1 if the digit is not legal for the specified base, otherwise return the the correct value (0 to radix -1).
Todo:
Implement in radix.c based on documentation contained in radix.h
char int2char ( int  radix,
int  value 
)

Get the character associated with a value in a specified radix

Parameters
radixthe radix in which you are working (2-36)
valueshould be in range 0 to radix - 1
Returns
the character '?' if the value is outside the radix range, otherwise return the character that reprensets that digit. For a radix greater that 10, use the uppercase letters 'A' to 'Z' to represent digits beyond a value of 9.
Todo:
Implement in radix.c based on documentation contained in radix.h
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].

Parameters
radixthe radix in which you are working (2-36)
valuethe value to print out.
Todo:
Implement in radix.c based on documentation contained in radix.h
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

Parameters
radixthe radix in which you are working (2-36)
Returns
-1 if the value contains an illegal digit for the radix, otherwise return the value.
Todo:
Implement in radix.c based on documentation contained in radix.h
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.

Parameters
radixthe radix in which you are working (2-36)
Returns
-1 if the value contains an illegal digit for the radix, otherwise return the value.
Todo:
Implement in radix.c based on documentation contained in radix.h