Hi everyone,
This is my first post so go easy on me please :). I am trying to compile a simple program that takes two binary numbers and computes a third based on bit operations (i.e. C = A&B, C = A|B etc....) but I run into the "vector subscript out of range error" even though I have carefully tried to ensure that I'm not stepping out of index bounds.
Is anyone able to help me with this?
NOTE: The binary numbers are stored as vector arrays of type char
int main()
{
// Request and obtain valid decimal numbers
int A = obtaindec('A');
int B = obtaindec('B');
// Convert A and B to binary and store as vector<char> arrays
vector<char> Abin = dectobinstring('A', A);
vector<char> Bbin = dectobinstring('B', B);
// Create C based on the largest size of the other two
vector<char> Cbin;
if ( Abin.size() > Bbin.size() )
Cbin.resize(Abin.size());
else
Cbin.resize(Bbin.size());
int Cbinsize = Cbin.size();
for ( unsigned int x = 0; x < Cbinsize; ++x )
Cbin[x] = 48;
// Now recalculate C as the result of relational operations
// on A and B
for ( unsigned int x = 0; x < Cbinsize; ++x )
if ( Abin[x] == 49 && Bbin[x] == 49 )
Cbin[x] = 49;
cout << "\n\nA & B = ";
for ( unsigned int x = 0; x < Cbinsize; ++x )
cout << Cbin[x];
cout << endl;
}