I'm having trouble with part of my assignment. I'm supposed to take 2 decimal numbers change them into binary numbers, do AND and OR comparisons between those 2 binary numbers, change the resulting binary number into a decimal number and store it into an array.
Ex. decA = 53 decB = 26
binaryA = 110101
binaryB = 11010
---------------------
And comparison = 010000
OR camparison = 111111
The binary equivalent of the AND comp is: 16
The binary equivalent of the OR comp is: 63
What I decided to do was change the decimal numbers to bin and store it them in 2 arrays, and then compare those 2 arrays and that's where I'm stuck. I feel like its correct but I'm not getting the right results.
My code for decimal to binary work great. Here is my code for comparing both arrays:
//which bin number has more digits
int max;
if(indexB > indexC)
max = indexB;
else
max = indexC;
//AND comparison
int andComp[12];
int newmax = max;
while(newmax >= 0 )
{
int i = 0;
if( (binB[i] != 0) && (binC[i] != 0) )
andComp[i] = 1;
else andComp[i] = 0;
i++;
newmax--;
}
cout << "Comparing B and C: ";
for(int i = max - 1; i >= 0; i--)
cout << andComp[i];
cout << endl;