Here is an expression that produces a syntax error:
opcode >>> temp; In C ++, there is no built-in unsigned right shift operator? Need to do it yourself with masks?
Here is an expression that produces a syntax error:
opcode >>> temp; In C ++, there is no built-in unsigned right shift operator? Need to do it yourself with masks?
Whether a signed or unsigned shift is applied depends on the sign of the left operand. So just bring it to the required type.
And note that in the right shift of the sign type, the distribution of the sign bit (to distribute it or fill it with zeros) depends on the compiler.
True, I have not yet heard that the sign bit in this situation did not spread somewhere ...
int main(int argc, const char * argv[]) { int opcode = 0xFF000000; cout << (opcode >> 27) << endl; cout << ((unsigned int)opcode >> 27) << endl; } gives (VC ++ 2015)
-1 31 Source: https://ru.stackoverflow.com/questions/510776/
All Articles
((unsigned)opcode) >> temp? - VladDstruct Instruction { unsigned int opcode : 5; unsigned int flags: 1; ... }; ... Instruction inst; ... opcode = inst.opcode;struct Instruction { unsigned int opcode : 5; unsigned int flags: 1; ... }; ... Instruction inst; ... opcode = inst.opcode;- VladD