Negative numbers are stored as 2's complement in memory, how does the CPU know if it's negative or positive?

前端 未结 6 1929
误落风尘
误落风尘 2020-12-08 02:46

-1 can be represented in 4 bit binary as (2\'s complement) 1111

15 is also represented as 1111.

So, how does CPU differentiate between 15 and -1 when it get

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 03:24

    In 2's complement to represent 15 we require 5 bits the range for 2'complemnt is -16 to 15,so the value become 01111 here the MSB bit is 0 so its positive value for -1 it will become 11111

提交回复
热议问题