1
\$\begingroup\$

Fixed point numbers can be in many different forms depending on the number of bits before and after the decimal expressed as Qm.n.

Floating point numbers can be in many forms depending on the number of bits specified for the exponent and mantissa. The sign bit will always be there.

What methods exist to convert between these?

\$\endgroup\$
7
  • 2
    \$\begingroup\$ Are you talking about notation (designed to be human-readable) or encoding (designed for machine processing and communication) ? \$\endgroup\$
    – Ben Voigt
    Commented Oct 19, 2021 at 16:43
  • \$\begingroup\$ Like in the answer Marcus provided, I also think more in it as a method and not as a "formula". It may be also the case that you have two methods, since the IEEE floating point format includes a "sub-normal range" which, as the name implies, is not normalized with an implicit "1." bit. \$\endgroup\$
    – devnull
    Commented Oct 19, 2021 at 16:45
  • \$\begingroup\$ Is there some research paper or book that covers this topic? \$\endgroup\$
    – quantum231
    Commented Oct 19, 2021 at 16:57
  • 1
    \$\begingroup\$ "Handbook of Floating-Point Arithmetic" by Jean-Michel Muller is the classic reference I know. \$\endgroup\$
    – devnull
    Commented Oct 19, 2021 at 17:00
  • \$\begingroup\$ This question is not clear. When you say "convert" do you mean using pencil and paper or code? If code, in what language? \$\endgroup\$ Commented Oct 19, 2021 at 19:42

3 Answers 3

1
\$\begingroup\$

way to convert from a fixed point notation to a floating point notation?

Assuming:

  1. only normalized floating point representation
  2. two's complement for negative fixed point numbers
  3. -0.0 float will not be generated from fixed point
  4. add a rounding method of your preference (or none)

Exponent bias depend on the specific format, so it is ignored below (it is up to the decision on how to represent negative exponents)

For both directions:

if zero:
    return zero

There is no signed integer, there is fixed point number.

If you are not concerned with negative fixed point numbers, just skip step 1.

Fixed point to floating point:

  1. negative number (set float sign bit and transform the two's complement to the positive representation: overflow happens for the minimum value but may fit in the float representation)

  2. find the most significant '1'

  3. if fixed >= 1.0 and < 2.0, this is the mantissa, exponent = 0 (FINISH)

  4. If fixed >= 2.0, shift right to reach the the range in 3. The shift amount is the positive exponent

  5. If fixed < 1.0, shift left to reach the the range in 3. The shift amount is the negative exponent

Truncate or fill the mantissa with zeros to fit the floating point representation. Rounding may affect the exponent.

\$\endgroup\$
0
\$\begingroup\$

Well, you need to define a "true" value conversion for both formats and then apply that.

In other words, for your fixed-point format, you need to define what m and n are in your case; that would give you the dynamic range of that format. Then, you'd extract the position of the highest set bit to figure out what your floating point number's exponent needs to be – and then you'd shift your number by the bit positions necessary to make the rest fit into your mantissa.

\$\endgroup\$
1
  • \$\begingroup\$ I have made the last line of question clearer. \$\endgroup\$
    – quantum231
    Commented Oct 19, 2021 at 19:38
0
\$\begingroup\$
  1. Express your signed fixed-point number as a signed integer. That is, treat the binary value as though it were simply a signed integer and determine that value.

  2. Use floating-point division to divide the signed integer by \$2^n\$, where \$n\$ is the number of fraction bits.

  3. There is no step 3. You are done.

\$\endgroup\$
4
  • \$\begingroup\$ There is no signed integer, there is fixed point number. Also, if I need to use floating point divider to do this task, it kinds of defeats the purpose really. \$\endgroup\$
    – quantum231
    Commented Oct 19, 2021 at 19:54
  • \$\begingroup\$ If the purpose is something other than converting a fixed point number to a float, then you need to tell us. What operations are allowed and which defeat the purpose? We can't help unless we know the (apparently arbitrary) rules. \$\endgroup\$
    – Supa Nova
    Commented Oct 19, 2021 at 20:24
  • 1
    \$\begingroup\$ You don't need a divider to divide by 2^N. \$\endgroup\$
    – user16324
    Commented Oct 19, 2021 at 20:24
  • \$\begingroup\$ @quantum231 I've been writing fixed-point, real-time, signal processing software for decades. But good luck to you. \$\endgroup\$ Commented Oct 19, 2021 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.