I'm trying the following code to combine ints, and then get the original ints back:
#include <iostream>
using namespace std;
int getleft(int n){
return (n >> 24);
}
int getright(int n){
return ((n << 8) >> 8);
}
int main(){
int i = 15;
int j = 28515;
int combined = i << 8 | j;
cout << getleft(combined) << endl;
cout << getright(combined) << endl;
}
But it doesn't work; getright() works and gives 28515, but getleft() gives 0.
What's my mistake?