Let's say I have a decimal like 0.9

To convert to Q0.27 I just multiply by 2^(27)

But with Q5.27, with 1 bit representing sign, how would I use the full range of bits available to me, to say convert 0.9 to a number between 16 and -16?

| improve this question | | | | |

You can't really use Q5.27 in 32-bit storage. You need at least one bit for the sign, so I guess you'd call it Q4.27 since the sign bit is implicit. The conversion from float is exactly the same as for Q0.27 except you can convert any numbers between -16 to just less than 16.

int(0.9 * 2^27)  = 0x07333333
int(-0.9 * 2^27) = 0xf8cccccd

As you can see you need the sign bit to represent a negative number.

-16 and 16 arise from:

0x7fffffff / (2^27) = 15.9999999925  (biggest +ve number)
0x80000000 / (2^27) = -16            (biggest -ve number)
| improve this answer | | | | |
  • $\begingroup$ thank you, i was confused about the prefix m of Qm.n and this clarified it $\endgroup$ – panthyon Sep 10 '15 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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