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...

1 answer below »



  1. 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.




1


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 abitis a binary digit. Abytecontains 8 bits.


The commands are as follows:


NOTTakes 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.


ANDTakes 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


Eg. operand 1 operand 2


result


ORTakes 2 operands and position, if either result will contain


a 0 (inclusive OR).


Eg. operand 1 operand 2


result


CONVERTTakes 1 operand and
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 * 2**7) + (0 * 2**6) + (0 * 2**5) + (1 * 2**4) + (0 * 2**3) + (1 * 2**2) + (1 * 2**1) + (0 * 2**0) = 150 in base 10


LSHIFTLogical 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


1. Otherwise the result is 0.



10010010 11001110 10000010

performs a bitwise logical OR. At each operand 1 or 2 or both contain a 1, the a 1. Otherwise the result will contain



10011001 11100101 11111101

converts it to a base 10 integer. Note:


2


You may assume N is valid, i.e. 0


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


From the data filebinaryData.txt, available on the class web site. Each line will contain:




  •  : one of the above commands, starting in column 1 of the data file




  •  : 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.




  •  : 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 (like the return (EXIT_FAILURE) shown in lecture), 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 namedsmall.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


3


----------------------------------------------------------


NOT 11010011 AND 10010010 OR 10011001 CONVERT 10010110 LSHIFT 11001101 WRONG 01010100 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 thepowfunction (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 isrequiredto 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 basetypeintto 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 CREATE ANY CLASSES!!!


DO NOTuse 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.


11001110 11100101

00101100 10000010 11111101 150 01101000

3
--- ERROR! Invalid Command ---


4

Answered Same DayApr 07, 2021

Answer To: This project will introduce you to some of the fundamental operations used on binary numbers (bit...

Aditya answered on Apr 07 2021
143 Votes
bitspattern/bin/Debug/bitspattern.exe
bitspattern/binarydata.txt
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
bitspattern/bitspattern.cbp

    
    
        
        
        
        
            
                
                
                
                
                
                    
                
            
            
                
                
                
                
                
                    
                
                
                    
                
            
        
        
            
            
        
        
        
            
            
            
            
        
    
bitspattern/bitspattern.depend
# depslib dependency file v1.0
1586295851 source:f:\cprograms\bitspattern\main.cpp
    
    
    
    
bitspattern/bitspattern.layout

    
    
    
        
            
        
    
bitspattern/main.cpp
#include
#include
#include
#include
using namespace std;
int power(int x)
{
int base =2;
int exp=x;
int result = 1;
while (exp != 0) {
result = result*base;
--exp;
}
return result;
}
void convertoperation(string x)
{
char char_array[8];
strcpy(char_array, x.c_str());
int operand1[8];
int sum =0;
int count = 7;
for (int i = 0; i < 8; i++)
{
if(char_array[i] == '1')
{
sum = sum+power(count);
}
count--;
}
cout<<"CONVERT "<}
void notoperation(string x)
{
char char_array[8];
strcpy(char_array, x.c_str());
int result[8];
for (int y=0;y<8;y++)
{
if(char_array[y] == '0')
{
result[y]...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here