binary representation of a fraction in two's complement

14.2k Views Asked by At

Could any one please explain what is a 16-bit two's-complement representation of -0.375 and the steps to calculate it? Also, what happens if I convert it back to decimal?

Thanks

2

There are 2 best solutions below

0
On

I try to offer my suggestion and it should not be taken as solution because I am not sure it is correct or not.

Notation: $[n]$ is called the greatest integer function. It is used to extract the integral part of the number $n$. Example: $[4.78] = 4$.

Step-1 … Convert $0.375$ to binary first.

--------- Multiply $0.375$ by $2 = 0.75$----record the result of $[0.75]$ as $A$, which is $0$ in this case.

--------- Let $X = 0.75 – [0.75] = 0.75 – 0 = 0.75$.

--------- Multiply $X$ by $2 = 1.5$----record the result of $[1.5]$ as $B$, which is $1$ in this case.

--------- Let $Y = 1.5 – [1.5] = 0.5$

--------- Multiply $Y$ by $2 = 1.0$----record the result of $[1.0]$ as $C$, which is $1$.

--------- Let $Z = 1.0 – [1.0] = 0$ and the process can be stopped as $0$ has been reached.

--------- $0.375_{(10)} = 0.ABC_{(2)} = 0.011_{(2)}$; where $A, B, C$ are digits of a number.

--------- [Check: $0.011_{(2)} = 0*2^{-1} + 1*2^{-2} + 1*2^{-3} = … = 0.375$]

Step-2 … Attach thirteen $0$’s to your result such that $0.375_{(10)} = 0.0110 0000 0000 0000_{(2)}$

Step-3 … Do the negation part (ie. The $2$’s complement part)

--------- Perform an $1$’s complement. Result $= 1.1001 1111 1111 1111_{(2)}$

--------- Add $1$ to the result and get $1. 1010 0000 0000 0000_{(2)}$.

0
On

Using fixed-point representation will work here. In such a representation the value of a given $n$-sequence of bits $\mathrm{fx}(b_{n-1} \ldots b_0)$ is scaled by a factor of $2^{-f}$. This has the effect of giving the $f$-least significant bits fractional weights.

For example, a $4$-bit, two's complement, fixed point representation with $2$ fractional bits would have a value $\mathrm{fx}(b_3 b_2 b_1 b_0)$ given by $2^{-2} b_0 + 2^{-1} b_1 + 2^0 b_2 - 2^1 b_3 = \frac{1}{4}b_0 + \frac{1}{2}b_1 + b_2 - 2 b_3$. Thus the smallest value $\mathrm{fx}(1000)$ is $-2$; the largest value $\mathrm{fx}(0111)$ is $\frac{7}{4}=1.75$. The smallest value less than zero $\mathrm{fx}(1111)$ is $-\frac{1}{4}=-0.25$.