3

So I'm learning about binary values and I'm trying to understand how to calculate the negative version of a number using the fixed point bit model.

In my textbook it says 000111.01 = 7.25 which I understand. But it's telling me -7.25 is 111000.11 which I don't understand how that's possible.

I know it's using the two's complement rule where it flips all the bits and adds a 1 at the end. But if I did the calculation: (1 * 2^5) + ( 1 * 2^4) + (1 & 2^3) + 0 + 0 + 0 + (1 * 2^-1) + ( 1 * 2^-2) it gives me 56.75.

I tried looking up tutorials online but I still can't figure out why -7.25 is 111000.11. I would appreciate it if someone could explain the mathematical process behind getting -7.25.

Grayish
  • 187
  • 1
  • 10

2 Answers2

2

You have an signed 8-bit 6Q2 format fixed point representation having a resolution of 2-2 (or 0.25). You can look at this purely arithmetically:

The int8_t value of 11100011 is -29, but with the fixed point scaling that is -29 x 0.25 = -7.25.

Or then in terms of 2's compliment bit values which for an 8 bit integer are:

-27 (-12810)
26 (6410)
25 (3210)
24 (1610)
23 (810)
22 (410)
21 (210)
20 (110)

but the Q2 fixed point shifts those place values by 2 as follows:

-25 (-3210)
24 (1610)
23 (810)
22 (410)
21 (210)
20 (110)
2-1 (0.510)
2-2 (0.2510)

Clifford
  • 88,407
  • 13
  • 85
  • 165
2

I know it's using the two's complement rule where it flips all the bits and adds a 1 at the end.

Under a scale factor where the binary point has been moved left two places, you need a modified rule: flip all the bits and add 1/4, or 0.01.

000111.01 = 7.25

Flip all the bits:

111000.10

Add 0.01:

111000.11

All that the fixed point convention has done is move the binary point. If we multiply 111000.11 by 4 (and truncate to stay within 8 bits), we get 100011.00. And that is -29. Exactly four times -7.25. Therefore if we divide 29 by 4, the process must reverse and go from 100011.00 to 111000.11. That's simply an arithmetic shift right. The process of sign extension is filling in 1's from the top, and the other bits are just shifting down. We end up with the .11.

Of course, here when I say "divide by 4", I mean divide by the regular integer 4, not the scaled 4 = 100.00. Under fixed point, we can use regular, un-adjusted multiplication and division to combine a fixed operand with a regular operand. FIXED x INT -> FIXED just uses regular multiplication. FIXED + FIXED -> FIXED uses regular addition. FIXED x FIXED -> FIXED requires renormalization. FIXED + INT -> FIXED requires conversion of the INT to FIXED.

Kaz
  • 55,781
  • 9
  • 100
  • 149