the code posted will compile only on x86 or x86-64 cpu architectures...

basicly the problem is that shr operator with signed arguments generates an unsigned shift which does not preserve the sign of the number....