Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include<cmath>
- using namespace std;
- void notFunction(int array1[]);
- void andFunction(int array1[], int array2[]);
- void orFunction(int array1[], int array2[]);
- void convertFunction(int array1[]);
- void LshiftFunction(int array1[], int shift);
- int main() {
- enum CommandList {NOT, AND, OR, CONVERT, LSHIFT};
- const int numberOfCommands = 5;
- ifstream dataFile;
- dataFile.open("binaryData.txt");
- char array1[8];
- int array2[8];
- // int shift;
- string commands[numberOfCommands];
- if(dataFile.is_open())
- {
- int count = 0;
- for(int i = 0; i < 10; i++)
- {
- dataFile >> commands[count];
- dataFile >> array1[count];
- }
- } else
- {
- cout<<"Error openning binaryData file.";
- return 0;
- }
- // notFunction();
- // andFunction(array1, array2);
- // orFunction(array1, array2);
- // convertFunction(array1);
- //cin >> shift;
- // LshiftFunction(array1, shift);
- return 0;
- }
- void notFunction(int array1[]){
- for(int i = 0; i < 8; i++){
- if(array1[i] == 0){
- array1[i] = 1;
- }else{
- array1[i] = 0;
- }
- }
- for(int i = 0; i < 8; i++){ //displays edited array
- //cout << array1[i] << " ";
- }
- }
- void andFunction(int array1[], int array2[]){
- int result[8];
- for(int i = 0; i < 8; i++){ //if array 1 and 2 have both 1 in same index, final result is 1
- if(array1[i] == 1 and array2[i] == 1){
- result[i] = 1;
- }else{ //otherwise final result for index is 0
- result[i] = 0;
- }
- }
- for(int i = 0; i < 8; i++){ //displays edited array
- //cout << array1[i] << " ";
- }
- }
- void orFunction(int array1[], int array2[]){
- int result[8];
- for(int i = 0; i < 8; i++){ //if array 1 or 2 have 1 in same index, final result is 1
- if(array1[i] == 1 or array2[i] == 1){
- result[i] = 1;
- }else{ //otherwise final result for index is 0
- result[i] = 0;
- }
- }
- }
- void convertFunction(int array1[]){
- int result=0, temp=0;
- int power = 8;
- for(int i = 0; i < 8; i++){
- power--;
- temp = (array1[i] * (pow(2,power)));
- result = result + temp;
- }
- //cout << result << endl;
- //cout << result;
- }
- void LshiftFunction(int array1[], int shift){
- //int array1[] = {1,1,0,0,1,0,1,1};
- for(int j = 0; j < shift; j++){ //shifts everything to the left by the amount of times indicated
- for(int i = 0; i<8; i++){
- array1[i]=array1[i + 1];
- }
- }
- for (int i = 0; i< shift; i++){ //replaces last numbers with 0
- array1[7 - i]=0;
- }
- for(int i = 0; i < 8; i++){ //displays edited array
- //cout << array1[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment