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

You want to read up on two's complement numbers. In short, the most significant bit can be used to determine if the number is negative.

I reread your question and you said you already understand two's complement. When dealing with negative numbers, the number of bits must be known to determine if the number is negative or not. A negative number must be sign extended to the required number of bits. Your example of -92 when stored in 32 bits would be 11111111111111111111111110100100.


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


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

No, you will need to know in advance whether a signed or unsigned representation / convention was used, and even if you know it is signed, then you will also need to know the encoding used to store the number.

If the 8-bit integer (i.e. byte) is signed, then as per Tom and 32bitkid, signed integers are usually stored in 2's complement, where the Most Significant Bit (MSB) will determine whether a number is negative or not.

e.g. In your example, the byte 10100100 could either represent the signed byte -92, since:

MSB : 1 means negative
Other 7 Bits 0100100 
Flip and add 1 => 1011011 + 1 = 1011100
From powers of two, right to left : 
0*2^0 + 0*2^1 + 1*2^2 + 1*2^3 + 1*2^4 + 0*2^5 + 1*2^6
= 4 + 8 + 16 + 64 
= 92 (and thus -92 because of the MSB)

OR if the value is an unsigned byte, then the MSB is just treated as the next power of 2, the same as all the lower bits

i.e. 10100100 could represent:

4 + 32 + 128 
= 164

(again, powers of two, right to left, and omitting the 0 powers of two)

The decision as to whether an integer should is signed or not, and the number of bits required, is generally determined by the range of values that you need to store in it. For example, a 32 bit signed integer can represent the range:

–2147483648 to 2147483647

Whereas an unsigned 32 bit integer can represent numbers from

0 to 4294967295