Ok. I think I see now. If the system() call returns "-1", this is the same as a binary number of all 1's (since the system presumably uses the two's-complement representation), and it looks like it is:
printf '%b', -1; print "\n"; # Output is: # 11111111111111111111111111111111
So, if we get -1 back, then I can just stop checking bits right there.
If the system() call does not return -1, but returns anything at all in those first 7 bits, then -- again -- I can stop checking anything else, because if those first 7 bits contain anything, that indicates that the program that was called received a signal and that's why it ended.
Finally, if the system() call does not return -1, and those first 7 bits are all zeros, then only at that point do those next 8 bits contain anything of interest (the exit status of the program called).
And to wrap this all up nicely, if the system() call returns 0, then that means all bits are off, thus:
and therefore the program that system() called evidently ran successfully.
Thank you!
In reply to Re^2: return value from system call, exit status, shift right 8, bitwise and, $?
by Anonymous Monk
in thread return value from system call, exit status, shift right 8, bitwise and, $?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |