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

前端 未结 5 436
别那么骄傲
别那么骄傲 2021-02-04 00:06

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

5条回答
  •  隐瞒了意图╮
    2021-02-04 00:40

    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.

提交回复
热议问题