I don't understand the output of this code:
main() {
int ret = ~(~0 <<5) << 2;
printf("ret: %d, %u\n", ret, ret);
}
output:
ret: 124, 124
If I process mentally, I do this:
- resolving ~0 gives binary 1
- resolving ~0 << 5 gives binary 100000
- resolving ~(~0 << 5) gives binary 011111
- resolving ~(~0 << 5) << 2 gives binary 111100
- convert binary 111100 to decimal gives 60
What did I do wrong ?