I am reading some C text. In the Negative and Positive Values session, the author mentioned several ways of representing a negative number in binary form.
I understood a
If you have the value in memory, cast it to a signed in the same size and test if it’s less than zero. So, if ((int)value < 0)
.
If you’re trying to parse a binary constant from a string, you need to know the format of the number. However, two’s-complement has been universal for fifty years now. (The one exception is binary-compatible support for certain old Unisys mainframes that are still being used.) For that, you just need to look at the first bit (as the accepted answer says).