How to know if a binary integral number represents a negative number?

ipkiss picture ipkiss · Oct 17, 2011 · Viewed 31.5k times · Source

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 all of the way and was wondering if with a give binary number, can we determine if it is negative?

For example, the -92 has the 8-bit binary form: 10100100. But if we are given 10100100 can we say that is -92, and not other non-negative number?

Answer

Tom Zych picture Tom Zych · Oct 17, 2011

It depends on the representation, of course. In two's complement, which is widely used, you simply look at the most significant bit.