I've been planning to write a function that takes an int that has arguments encoded into it, IE: 100101010
Before I start writing, I created a test program to make sure I understand how to decode and encode the values. Encoding them worked immediately, but decoding them worked less successfully.
Below is the test code I've been using:
#include <iostream>
using namespace std;
enum Math_Init
{
INIT_SINE = 1, INIT_COS = 10, INIT_TAN = 100,
INIT_COT = 1000, INIT_SEC = 10000, INIT_CSC = 100000,
INIT_ALL = 111111
};
int main()
{
//cout << "Init Sine: " << INIT_SINE << endl;
//cout << "Init Sine | Init Cos: " << (INIT_SINE | INIT_COS) << endl;
//cout << "Init Sine | Init Cos | Init Sec: " << (INIT_SINE | INIT_COS | INIT_SEC) << endl;
//cout << "Attempting to Decode Bits..." << endl;
int c = /*(INIT_SINE | INIT_COS | INIT_SEC);*/ 100011;
cout << "Value of Bits: " << c << endl;
cout << "Is Sine Present? " << (c & 1 << 0) << endl;
cout << "Is Cos Present? " << (c & 1 << 1) << endl;
cout << "Is Tan Present? " << (c & 1 << 2) << endl;
cout << "Is Cot Present? " << (c & 1 << 3) << endl;
cout << "Is Sec Present? " << (c & 1 << 4) << endl;
cout << "Is Csc Present? " << (c & 1 << 5) << endl;
system("PAUSE");
return 0;
}
I've not been able to isolate / decode the values in the int, what am I doing wrong? I've been looking at this to try and fix the issue with no luck: http://www.cprogramming.com/tutorial/bitwise_operators.html
c & (1 << 0). This means the very same thing, but not everyone remembers all the operator precedence rules.(c & INIT_SINE)and not(c & (1 << 0)).