How are negative numbers represented in 32-bit signed integer?

后端 未结 7 1872
时光取名叫无心
时光取名叫无心 2020-12-02 01:30

How are negative number represented in 32-bit signed integer? Is it two\'s or one\'s complement? or the last bit on the left is like a flag? For example: (-10)

7条回答
  •  臣服心动
    2020-12-02 02:11

    Most computers these days use two's complement for signed integers, but it can vary by hardware architecture, programming language, or other platform-specific issues.

    For a two's-complement representation, the most-significant ("leftmost") bit is referred to as the sign bit, and it will be set for a negative integer and clear for a non-negative integer. However, it is more than just a "flag". See the Wikipedia article for more information.

提交回复
热议问题