clairify bitwise operators

So a 'potential' assingment asks to use bitwise operators on an int. the paper give some info but i am kinda confused as to what is being done in memory.

can someone provide examples for <<, >>, &, |. Thanks
If i is an int, then:

i << 1 equals the value of i with all bits shifted left one (ie, has the value i * 2)
i >> 1 equals the value of i with all bits shifted right one (ie, has the value i / 2)
i & 1 equals the value of i bitwise-anded with 1 (ie, has value 1 if i is odd, 0 if even)
i | 1 equals the value of i bitwise-ored with 1 (ie, if i is even, has value i + 1, otherwise value i)
how do i retrieve an int using bitwise operators without changing original?

1
2
3
4
5
6
int origianl = 12,input,retrieve;
// get input from user: original is used to store multiple integers
original <<= 4;
original |= input;
// now how do i get input back 
retrieve = ??????
An int can only hold one value at a time.

1
2
3
4
int original_value = 12;
int inputted_value;   // read this from user

int new_value = ( original_value << 4 ) | inputted_value;


original_value is still 12,
inputted_value is still the value the user typed in,
new_value is the new value.
Topic archived. No new replies allowed.