How to represent a negative number with a fraction in 2's complement?

此生再无相见时 提交于 2019-11-30 04:54:52

With decimal number systems, each number position (or column) represents (reading a number from right to left): units (which is 10^0), tens (i.e. 10^1),hundreds (i.e. 10^2), etc.

With unsigned binary numbers, the base is 2, thus each position becomes (again, reading from right to left): 1 (i.e. 2^0) ,2 (i.e. 2^1), 4 (i.e. 2^2), etc.

For example

2^2 (4), 2^1 (2), 2^0 (1).

In signed twos-complement the most significant bit (MSB) becomes negative. Therefore it represent the number sign: '1' for a negative number and '0' for a positive number.

For a three bit number the rows would hold these values:

-4, 2, 1
 0  0  1 => 1
 1  0  0 => -4
 1  0  1 => -4 + 1 = -3

The value of the bits held by a fixed-point (fractional) system is unchanged. Column values follow the same pattern as before, base (2) to a power, but with power going negative:

2^2 (4), 2^1 (2), 2^0 (1) . 2^-1 (0.5), 2^-2 (0.25), 2^-3 (0.125)

-1 will always be 111.000
-0.5 add 0.5 to it: 111.100

In your case 110100.10 is equal to -32+16+4+0.5 = -11.5. What you did was create -12 then add 0.5 rather than subtract 0.5.

What you actually want is -32+16+2+1+0.5 = -12.5 = 110011.1

you can double the number again and again until it's negative integer or reaches a defined limit and then set the decimal point correspondingly.

-25 is 11100111, so -12.5 is 1110011.1

So;U want to represent -12.5 in 2's complement representation

12.5:->> 01100.1

2's complement of (01100.1):->>10011.1

verify the ans by checking the weighted code property of 2's complement representation(MSB weight is -ve). we will get -16+3+.5=-12.5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!