I am working on a problem and I am stuck. I need to create a stack with the container being an unsigned int. I tried to put in numbers up to four bits each and have the program read the numbers individually. This is the code I am using:
void push(int n) //item n is pushed onto the stack, throw exception on full stack
{
string str="Error";
if (isFull())
throw str;
else
{
n = n & 0x0F;
Integer = Integer << 2;
Integer = Integer | n;
cout << Integer << endl;
}
}
When I have tested it, the program is reading the numbers as one whole number. For example, I put in the number 2, and it displays the number 2. Then I put in 2 again, but this time it displays the number 10, instead of 2 2. Can anyone help me?
Ok, thank you. All I need to do now is figure out how to make the program read the binary. And it should be Integer << 4 but I was playing with it trying to figure out what it was doing.