I am still struggling with bitwise operators using Ruby.
Getting a value 11100 (28 in base 10) (from a bitstream), I’d like to see it as -4, that is signed integer on 5 bits.
How would you proceed ?
I know the generic pseudo-algorithm says :
-X = “/X +1” ie : to get the opposite of X, first flip bits of X, then increment by 1. But here I am stucked !
Iff the left most bit is a 1 then it is negative number.
So take your 28 and subtract 32 (2^5) to get -4.
But -2 would be 11110