- Jun 15, 2005
- 1,688
- 0
- 76
I need some help with bitwise operations. I apparantly did not learn them last semester and the teacher has now decreed unless i learn them fast I am ******!!
Disclaimer: THIS IS NOT A HOMEWORK ASSIGNEMENT, IT IS AN ICA THAT I HAVE ALREADY FAILED!!!
Ok.
So here are the instructions:
1. Declare 2 arrays of char, both of length 256.
2. Prompt the user to enter some text, then accept the text into one of the arrays of char. Use and operation from the cstring header to copy the input string into the second array of char.
3. Proceeding character by character up to BUT NOT INCLUDING null, perform the following bitwise operation on each character in the second array of char:
a)Use an AND mask to clear (make equal to 0) bits 6 and 7.
b)Use an OR mask to set (make equal to 1) bits 0 and 1.
c)Perform a left shift of one bit position.
4. Display both the original string and the modified string, with suitable documentation.
i have the basic shell for the program, but i dont know how to write the bitwise operations to dop as requested. I know they will belong in the for loop.
#include <iostream>
#include <cstring>
using namespace std;
int main(int argc, char**argv)
{
char line[256];
char modify[256];
cout << "Please Enter a short message: " << endl;
cin.getline(line,256);
cout << endl;
strcpy(modify, line);
for(int n=0; modify[n]!=0; n++)
{
}
cout << "The original string Read: " << line << endl;
cout << "The scarambled string Reads: " << modify << endl;
return 0;
}
I woyuld appreciate an explaination as to what i need to do to get this operation to work.
Disclaimer: THIS IS NOT A HOMEWORK ASSIGNEMENT, IT IS AN ICA THAT I HAVE ALREADY FAILED!!!
Ok.
So here are the instructions:
1. Declare 2 arrays of char, both of length 256.
2. Prompt the user to enter some text, then accept the text into one of the arrays of char. Use and operation from the cstring header to copy the input string into the second array of char.
3. Proceeding character by character up to BUT NOT INCLUDING null, perform the following bitwise operation on each character in the second array of char:
a)Use an AND mask to clear (make equal to 0) bits 6 and 7.
b)Use an OR mask to set (make equal to 1) bits 0 and 1.
c)Perform a left shift of one bit position.
4. Display both the original string and the modified string, with suitable documentation.
i have the basic shell for the program, but i dont know how to write the bitwise operations to dop as requested. I know they will belong in the for loop.
#include <iostream>
#include <cstring>
using namespace std;
int main(int argc, char**argv)
{
char line[256];
char modify[256];
cout << "Please Enter a short message: " << endl;
cin.getline(line,256);
cout << endl;
strcpy(modify, line);
for(int n=0; modify[n]!=0; n++)
{
}
cout << "The original string Read: " << line << endl;
cout << "The scarambled string Reads: " << modify << endl;
return 0;
}
I woyuld appreciate an explaination as to what i need to do to get this operation to work.