In C, I am given an int x
and have to use only the following bitwise and logical operators to multiply x
by 2: << >> ~ | ^ &
. The operators + and *
are specifically forbidden.
This would normally be easy, as I could just do x << 1
. However, the goal of this problem is to assume that that x contains a single precision float
value.
I believe the point of pretending that x
is a float
is to challenge us to to think about floats in bits and how to properly multiply them by applying the previously mentioned shift and logical operators.
When it comes to shifting floating point values, my current understanding is that a float's bits can be misrepresented when shifted. Is this correct? If not, why? Otherwise, my understanding is correct and I'm stuck on how to go about implementing this. Any help would be greatly appreciated!