Help with Integer variable as stack

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?
program is reading the numbers as one whole number
Integer is one whole number:
1
2
Integer = Integer << 2; //Integer = Integer * 4
Integer = Integer | n; //Integer = Integer + n 
2 * 4 + 2 == 10

You need to write another function which will parse one whole number Integer as a sequence of 2 byte integers

Also shouldn't it be Integer << 4?
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.
Topic archived. No new replies allowed.