Asking this question again. This is all the information I have on the problem.
Problem Statement: This project will introduce you to some of the fundamental operations used on binary numbers (bit patterns) in digital computers. It will also give you a good understanding of how to use and manipulate 1-dimensional arrays. Note that bit pattern manipulations are required for processing digital media of all forms. These bit patterns are at the very core of our current technology, from the mobile phone to the most powerful supercomputer.
In the program, you must read commands which will require you to perform some operation on either one or two bit patterns, determine the result of the operation, and output accordingly. The binary operands will contain exactly 8 bits, where a bit is a binary digit. A byte contains 8 bits.
The commands are as follows:
NOT Takes 1 operand and performs a bitwise logical NOT. At each position, if the operand has a 0, the result will contain a 1. If the operand has a 1, the result will contain a 0. Eg. operand 11010011 result 00101100 In logical operations, a 1 represents TRUE and a 0 FALSE. AND Takes 2 operands and performs a bitwise logical
AND. At each position, if both operand 1 and operand 2 contain a 1, the result will be a 1. Otherwise, the result is 0. Eg. operand 1 10010010 operand 2 11001110 results 10000010
OR Takes 2 operands and performs a bitwise logical OR. At each position, if either operand 1 or 2 or both contain a 1, the result will contain a 1. Otherwise, the result will contain a 0 (inclusive OR). Eg. operand 1 10011001 operand 2 11100101 results 11111101
CONVERT Takes 1 operand and converts it to a base 10 integer. Note: we will let every bit in these binary numbers represent part of a positive binary integer, i.e. there is no "sign" bit. Thus we can only represent positive integers in the range from 0 thru (28 - 1). Eg. operand 10010110 result = (1 * 27) + (0 * 26) + (0 * 25) + (1 * 24) + (0 * 23) + (1 * 22) + (1 * 21) + (0 * 20) = 150 in base 10
LSHIFT Logical Shift to Left Takes 1 operand and an integer N as input. The bit values are shifted N positions to the left. Data "pushed off" the left end is lost. Zeroes replace the lost bits. Eg. operand 1 11001101 N = 3 result 01101000 3 You may assume N is valid, i.e. 0 <= N <= 8 Shifts are used to multiply and divide by powers of 2. If a positive integer is left shifted N bits, the result is the original number multiplied by 2N, barring overflow.
Input
: one of the above commands, starting in column 1 of the data file
<1st operand>: the 1st binary operand, a sequence of eight 0's and 1's starting in column 10. Shift commands will also have an integer following the binary number, starting in column 20.
<1st operand>: the 2nd binary operand, for commands which require it, starting in column 20
BAD DATA: you must check for invalid command names. You may assume that the binary operands are all correctly given in the data file
You may hard code the file name into your program. You are required to implement a check to see if the data file has opened successfully, and if it has not, your code must terminate the program with a descriptive error message. You can use either the return function and implement a second return in main or you may use the exit function and exit from any function in the program, as shown in the same lecture.
An additional test data file, which is smaller and may be used for your early testing, is also given on the web site and is named small.txt.
Output and an example:
As usual, echoprint all input values. Then output in a suitable fashion the results of the operation performed, and any necessary error messages. Do follow the style guidelines in making your output neat and readable. Here is sample output, using the smaller test data file as input:
- *
- Eight Bit Binary Number Manipulator *
- *
COMMAND Operand #1 Operand #2 Shift Result
4
NOT 11010011 00101100 AND 10010010 11001110 10000010 OR 10011001 11100101 11111101 CONVERT 10010110 150 LSHIFT 11001101 3 01101000 WRONG 01010100 --- ERROR! Invalid Command --- Execution Completed.
Use Of Functions
Part of your grade on this and all future course programming projects will be determined by how well you utilize functions and parameters appropriately. Start by working on a good design, structure chart, etc. Your program must contain at least seven functions other than main, and represent a modular, cohesive design following class style guidelines.
Note: it is not efficient to use the pow function (in the cmath header file) to calculate the integer powers of 2. Since pow uses doubles and must do data type conversions each time it is called, it is not efficient for the integers in this program. Instead, it is better and it is required to write up your own function to calculate integer powers of 2 (and this function may not call pow!).
Use Of Data Structures and Data Types
The major goal of this project is to familiarize you thoroughly with various aspects of processing standard core C++ language 1-dimensional arrays. For this reason, you must use 1-dimensional arrays of basetypeint to store the binary numbers (bit patterns). Then use what you have learned about arrays to perform the required manipulations on them. You may NOT use C++ strings to store the binary operands. You must use the C++ typedef construct to set up your arrays and pass them as parameters.
You are required to use C++ string class variables to store and compare the commands. The ONLY classes you may use in this program are the standard C++ string class (for the commands only) and the standard basic iostream classes (for standard input and output).
DO NOT use the C++ operators for bitwise operations to perform your bit pattern manipulations. You are required to set up the arrays and write the code to do these tasks yourself.
Note: by convention, bits in a byte are numbered starting from 0 going from left to right. This is consistent with an array with indices from 0 through 7.
File 1: Binary Data (Given to us, used to be put into the program)
CONVERT 00000000
NOT 00000000
AND 00001111 11110000
OR 00001111 11110000
CONVERT 11111111
IR 11111111 00000000
NOT 11001100
LSHIFT 11001101 3
CONVERT 01011101
AND 10111011 00111000
LSHIFT 11001101 8
OR 10000001 10011001
CONVURT 10101010
LSHIFT 11111111 1
File 2: Small Text: (Given to suppose to put it into the program)
NOT 11010011
AND 10010010 11001110
OR 10011001 11100101
CONVERT 10010110
LSHIFT 11001101 3
WRONG 01010100 10101010
Aucun commentaire:
Enregistrer un commentaire