Computer Organization
Computer Science 251
Dickinson College
Spring Semester 1997
TTh 2:00 - 3:15
South College 04
Project #3 - Base Conversion and Data Representation
Due 2/20/97
Introduction:
In this project you will be writing functions that convert between base2 and base10 numbers. While our simulated computer will not use these functions in their hardware it will make it easier for us to interact with the computer. You will also get practice using the BitData class which will be the primary means for passing information between the components of our computer (It will be the wires between our components.)
The Project resource page contains links to UNIX and C++ references that you may find helpful.
Files For This Project:
If you need to know how and where to get these files refer to the documentation for Project #1.
New Files:
- BaseConv.h
- Defines the 3 functions ToBase2, ToBase10 and TwosComp that are needed to convert positive and negative integers between base2 and base10 representations.
- InfoTypes.h
- Defines the class BitData that will be used to manipulate multiple bit information. This includes passing data between the components of our computer. Defines an overloaded insertion operator for the BitData class.
- InfoTypes.cpp
- Implements the member functions of the BitData class. Also implements the overloaded insertion operator for BitData so cout << can be used with BitData types.
Files From Past Projects:
- From Project #1.
-
- From Project #2.
-
The Assignment:
I have broken this project up into 4 parts. It seems to me that it would be logical to do the first part of the project and check to see if it works then proceed to the second part. After checking the second part then do the third part. You are however, entitled to proceed in any manner you find suitable.
- Part 1:
- Get the BaseConv.h file. Read through it and be sure you understand what you are supposed to be implementing.
- Write a rough draft of the part of your design document for the functions ToBase10 and ToBase2 for unsigned numbers (i.e. all positive numbers).
- Create the BaseConv.cpp file and implement ToBase10 and ToBase2.
- ToBase10 takes a BitString type (Note: The BitString type is defined in the Logic.h header file) and a Boolean type. This function converts the Base2 value contained in the BitString type parameter into a base10 value that is returned as a DecValue (Note: The DecValue type is defined in the Logic.h header file). The BitString can contain anywhere between 1 and 16 bits. The BitString (like any C string) must be null terminated. The Boolean type parameter indicates if the BitString should be interpreted as an unsigned number or as a 2's complement number. For part 1 of the project assume that all numbers are unsigned.
- ToBase2 takes a DecValue type, a BitString type, an integer type and a Boolean type. This function converts the base10 value contained in the DecValue type parameter into a base2 value that is returned in the BitString type parameter. The resulting bit string will contain the number of bits indicated by the integer parameter. The Boolean type parameter indicates if the DecValue should be converted to an unsigned base2 number or to a 2's complement base2 number. For part 1 of the project assume that all numbers are unsigned. You need to make sure to null terminate the BitString that you return so that it is a valid C string.
- Add the BaseConv.cpp file to your Makefile.
- Write the test cases for ToBase2 and ToBase10 in your main.cpp file.
- Test and debug your ToBase2 and ToBase10 functions.
- Make any corrections to your design document.
- Part 2:
- Write a rough draft of the section of your design document for the TwosComp function.
- Implement the TwosComp function.
- The TwosComp function takes a BitString type. This function takes the two's complement of the base2 value contained in the BitString parameter. The resulting value should overwrite the old contents of the BitString parameter. Both the incoming and outgoing BitString types must be null terminated to be valid C strings.
- Test and debug the TwosComp function.
- Make any corrections to your design document.
- Part 3:
- Augment the ToBase10 and ToBase2 sections of your design document to account for 2's complement signed numbers.
- Change your ToBase10 and ToBase2 functions to accept and return negative values represented in 2's complement format if requested by the Boolean type parameter. This will make use of your TwosComp function.
- Test and debug your new versions of ToBase2 and ToBase10.
- Make any corrections to your design document.
- Part 4:
NOTE: You do not need to include any comments on part 4 of this project in your design document. This part of the project is only to familiarize you with the BitData class that you will be using extensively for the remainder of the semester.
- Get the InfoTypes.h and InfoTypes.cpp files.
- Read through the InfoTypes.h and InfoTypes.cpp files to be sure you understand what all of the code does and how to use all of the member functions.
- Add InfoTypes.cpp to your Makefile.
- Write a function in main.cpp to perform the following operations:
NOTE: These operations all make heavy use of the member functions of the BitData class.
- Create 2 four bit BitData variables initialized to 0000.
- Create an 8 bit BitData variable initialized to 01010101.
- Create a 16 bit BitData variable initialized to all 0's.
- Print out the values of all of your variables in both base2 and base10.
- Put the value 0011 into one of your 4 bit BitData variables.
- Copy the value of the BitData variable from your last step into the other 4 bit BitData variable using the overloaded assignment operator.
- Print out the values of both of your 4 bit BitData variables in base2.
- Set the value of one of your 4 bit BitData variables to all 1's.
- Set the 4 Most Significant Bits of the 8 bit BitData variable to the contents of one of your 4 bit BitData variables.
- Set the 4 Least Significant Bits of the 8 bit BitData variable to the contents of your other 4 bit BitData variable.
- Print out the contents of your 4 and 8 bit BitData variables in base2.
- Set the upper half of your 16 bit BitData variable to the contents of your 8 bit BitData variable.
- Set the lower half of your 16 bit BitData variable to the contents of your 8 bit BitData variable.
- Print out the contents of you 16 bit BitData variable in base2.
- Print out the odd number bits of your 16 bit BitData variable.
- Be sure that you understand why everything you just did works and why it works the way it does.
Submitting Your Solution:
For this project you need to submit 3 files.
- BaseConv.cpp - contains your implementation of the functions prototyped in the BaseConv.h header file.
- Main.cpp - contains your main() function and all of your test code.
- Design Document - the design document describes your implementation and testing strategies.
If you need to refresh your memory on how to submit the files refer to the Project #1 documentation.
These pages designed and maintained by Grant Braught
Braught@Dickinson.edu