My Project
Functions
numconv.h File Reference

Defines interface of numconv.c functions (do not modify) More...

Go to the source code of this file.

Functions

char int2char (int radix, int digit)
 
int char2int (int radix, char digit)
 
void divRem (int numerator, int divisor, int *quotient, int *remainder)
 
int ascii2int (int radix, const char *str)
 
void int2ascii (int radix, int value)
 
double ascii2double (int radix, const char *str)
 

Detailed Description

This file defines the interface to a C file numconv.c that you will complete. You will learn how to use the C language operators for address-of (&), and dereferencing pointers *). This will serve as a model when you implement the same functions in LC3 assembly language.

Function Documentation

double ascii2double ( int  radix,
const char *  str 
)

Convert the string to a double. This function is for extra credit.

Parameters
radix- the base you are working in (2-36)
str- the string may contain the character '.' and the characters that follow it are the fractional portion of the number,
Returns
the value as a double or -1.0 on error.
Todo:
implement in numconv.c based on documentation contained in numconv.h.
int ascii2int ( int  radix,
const char *  str 
)

Convert a string to an integer value

Parameters
radix- the base you are working in (2-36)
str- the string
Returns
the number represented by the string or -1 on error
Todo:
implement in numconv.c based on documentation contained in numconv.h.
int char2int ( int  radix,
char  digit 
)

Return the value corresponding to the character.

Parameters
radix- the base you are working in (2-36)
digit- character '0' .. '9' or 'A'..'Z' 'a' .. 'z'
Returns
value in the range of 0 - (base-1) if c is valid in the base. Otherwise return -1;
Todo:
implement in numconv.c based on documentation contained in numconv.h.
void divRem ( int  numerator,
int  divisor,
int *  quotient,
int *  remainder 
)

Calculate both the quotient and remainder of a division and return the values via pointers. You may use the C operators for division (/) and modulus (%). However, you might want to write a loop to using repeated subtraction do the calculations to help you understand how you will implement this in LC3 assembly language (which has no operators for division or modulus).

Parameters
numerator- non-negative value for numerator
divisor- a positive value to divide by
quotient- a pointer to the location to store the result of division
remainder- a pointer to the location to store the remainder
Todo:
implement in numconv.c based on documentation contained in numconv.h.
void int2ascii ( int  radix,
int  value 
)

Print a number in the specified base. Use the C call putchar() to print a single character obtained using int2char(). This corresponds to the OUT instruction of the LC3 OS. You may not use any other C I/O routine for printing. This function MUST be implemented recursively. Your program can not use arrays or strings in C, even if you know about them.

Parameters
radix- the base you are working in (2-36)
value- the number to print
Todo:
implement in numconv.c based on documentation contained in numconv.h.
char int2char ( int  radix,
int  digit 
)

Return the character corresponding to the digit.

Parameters
radix- the base you are working in (2-36)
digit- a value in the range of 0 - (base-1)
Returns
- character '0' .. '9' or 'A'..'Z' if the value is legal. Otherwise return '?'
Author
your name goes here
Todo:
implement in numconv.c based on documentation contained in numconv.h.