After messing with the bit-wise operators I sort of have an understanding of what is happening for of them, however I'm still a little confused about them. I was wondering if my observations were correct about them. I was wondering if you guys could explain what exactly I'm doing? I believe I understand the << operator however the other examples I have no idea what they're doing. I think the ~ operator makes the number negative and then subtracts by 1. But the rest of these operators are a little confusing. Not only that but what is the true purpose of these operators anyways?
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int test;
for (int a = 0; a < 5; a++) {
cout << "a << i: ";
//Equal to (a = a * 2)
for (int i = 1; i < 11; i++) {
test = a << i;
cout << test << ' ';
}
cout << endl;
cout << "~a ";
//Equal to ((a = a * -1) -1)
for (int i = 1; i < 11; i++) {
test = ~a;
cout << test << ' ';
}
cout << endl;
cout << "a ^ i: ";
for (int i = 1; i < 11; i++) {
test = a ^ i;
cout << test << ' ';
}
cout << endl;
cout << "~a ^ i: ";
for (int i = 1; i < 11; i++) {
test = ~a ^ i;
cout << test << ' ';
}
cout << endl;
cout << '~' << a << " & i: ";
for (int i = 1; i < 11; i++) {
test = ~a & i;
cout << test << ' ';
}
cout << endl << endl;
}
}