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
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 = ??????