2's complement representation of fractions?

后端 未结 3 1739
别跟我提以往
别跟我提以往 2021-01-21 03:02

I\'m a little lost on this. I need to use two fractional bits 0.(a-1)(a-2)

Like that, now I can use .00 .01 .10 and .11 But I nee

3条回答
  •  遇见更好的自我
    2021-01-21 03:27

    see it this way:

    you have normal binary representation

    let's assume 8 bit words ...

    the first bit (MSB) has the value 128, the second 64, and so on ...

    in other words the first bit (MSB) is 2^7 ... the second bit is 2^6 ... and the last bit is 2^0

    now we can assume our 8 bit word has 2 decimal places ....

    we now start with the first bit (MSB) 2^5 and end with the last bit beeing 2^-2

    no magic here ...

    now to turn that into binary complement: simply negate the value of the first bit

    so instead of 2^5 it would be -2^5

    so base 10 -0.75 would be in binary complement
    111111.01 ...
    (1*(-32) + 1*16 + 1*8 + 1*4 + 1*2 +1*1 + 0*0.5 + 1*0.25)
    (1*(-2^5) + 1*2^4 + 1*2^3 + 1*2^2 + 1*2^1 +1*2^0 + 0*2^(-1) + 1*2^(-2))

提交回复
热议问题