How to find exponent and mantissa from a Q Format

S

sankar

Hi,

I am using a Q14.18 value. There are tables used
in my program which are being indexed by the exponent and mantissa
parts of the corresponding floating point value.

So how can I get the exponent and mantissa parts of a floating point
number from its Q format representation.


Please do help.
TIA.
 
K

Keith Thompson

sankar said:
I am using a Q14.18 value. There are tables used
in my program which are being indexed by the exponent and mantissa
parts of the corresponding floating point value.

So how can I get the exponent and mantissa parts of a floating point
number from its Q format representation.

Standard C has nothing called "Q14.18" or "Q format". If you can
specify the format, we might be able to help.
 
B

Brad Griffis

sankar said:
Hi,

I am using a Q14.18 value. There are tables used
in my program which are being indexed by the exponent and mantissa
parts of the corresponding floating point value.

So how can I get the exponent and mantissa parts of a floating point
number from its Q format representation.


Please do help.
TIA.

I have only seen the "Q" notation used for doing fixed-point math. That
is, a Q14.18 number has 14 binary digits to the left of the implied
decimal point and 18 digits to the right of the implied decimal point.
You are talking about floating point, exponents, and mantissas. The
fixed point terminology would involve an integer and a fractional piece.
I've never heard anyone apply this terminology to floating point. Is
that truly what you're doing or are you using the wrong terms? In fixed
point you would just right-shift this number by 18 and you've got your
index.

Brad
 
T

Tim Olson

| Hi,
|
| I am using a Q14.18 value. There are tables used
| in my program which are being indexed by the exponent and mantissa
| parts of the corresponding floating point value.
|
| So how can I get the exponent and mantissa parts of a floating point
| number from its Q format representation.

You would be better off asking this question in comp.dsp, where dealing
with fixed-point (Q-format) numbers is common.

Q14.18 specifies a fixed-point value of 32 bits with a 14-bit integer
and 18-bit fraction, usually in 2's-complement (signed) format.

To get the equivalent floating-point value, you need to first get the
magnitude by taking the 2's complement of the value if the sign bit is
set. Then "normalize" the Q14.18 value by shifting it left until the
most-significant bit is a '1', and counting the number of times you
shift. The exponent is then:

14 - shift_amount - 1

and the mantissa is the value after you normalize in 1.31 format.

Example:

value = 26.85

Q14.18 representation = 00000000011010.110110011001100110

shift left 9 times to get a '1' in the most-significant bit:

11010110110011001100110000000000

exponent is 14-9-1 = 4

mantissa is 1.1010110110011001100110000000000


-- Tim Olson
 
J

Jerry Avins

Tim said:
| Hi,
|
| I am using a Q14.18 value. There are tables used
| in my program which are being indexed by the exponent and mantissa
| parts of the corresponding floating point value.
|
| So how can I get the exponent and mantissa parts of a floating point
| number from its Q format representation.

You would be better off asking this question in comp.dsp, where dealing
with fixed-point (Q-format) numbers is common.

Q14.18 specifies a fixed-point value of 32 bits with a 14-bit integer
and 18-bit fraction, usually in 2's-complement (signed) format.

To get the equivalent floating-point value, you need to first get the
magnitude by taking the 2's complement of the value if the sign bit is
set. Then "normalize" the Q14.18 value by shifting it left until the
most-significant bit is a '1', and counting the number of times you
shift. The exponent is then:

14 - shift_amount - 1

and the mantissa is the value after you normalize in 1.31 format.

Example:

value = 26.85

Q14.18 representation = 00000000011010.110110011001100110

shift left 9 times to get a '1' in the most-significant bit:

11010110110011001100110000000000

exponent is 14-9-1 = 4

mantissa is 1.1010110110011001100110000000000

And in most floating-point formats, the 1 before the binary point is
omitted from storage, reinserted by the ALU.

Jerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top